Tutorial

1.8 When an order fails

Add a cap to a mug:

curl -X POST http://localhost:5080/orders -H 'Content-Type: application/json' \
  -d '{"customerId":"ada","lines":[{"sku":"MUG","quantity":1},{"sku":"CAP","quantity":1}]}'
"CAP is out of stock."

That is a 422. The log shows the cart was priced, then the train stopped:

info: Shopfront.Trains.PlaceOrder.Junctions.PriceCartJunction[0]
      Priced 2 lines at 30.50
fail: Trax.Effect.Services.ServiceTrain.ServiceTrain[0]
      Caught Exception (Trax.Core.Exceptions.TrainException) with Message (CAP is out of stock.).

ReserveStockJunction threw, so no payment was taken and no order was confirmed. Run rethrew the exception as it was thrown, which is how Program.cs could turn it into a 422. Because the catalogue reserves all or nothing, the mug was not reserved either.

Send an empty cart and the order stops one junction earlier, at pricing:

curl -X POST http://localhost:5080/orders -H 'Content-Type: application/json' \
  -d '{"customerId":"ada","lines":[]}'
"The cart is empty."

Stop the application with Ctrl+C.

SDK Reference

Junctions | Chain | Run / RunEither | TrainException | AddTrax / AddEffects | UseInMemory | SaveTrainParameters | AddMediator


Next: 1.9 When the chain does not fit