Nova · Endpoints

Endpoint error

A call that fails runs its onError steps and no others. Inside them @error is what went wrong: its status, and a message.

The action, as it is written
{
  id: 'endpoint-error',
  data: { booked: false, problem: '', status: 0 },
  layout: {
    component: 'Stack',
    children: [
      {
        if: '$.booked',
        then: { component: 'Text', children: 'Booked.' },
      },
      {
        if: '$.problem',
        then: {
          component: 'Text',
          children: '{{$.status}}: {{$.problem}}',
        },
      },
      {
        component: 'Button',
        ref: 'book',
        children: 'Book seat C4',
      },
    ],
  },
  endpoints: {
    book: {
      url: '/examples/endpoint-error/bookings',
      method: 'POST',
    },
  },
  triggers: [
    {
      event: 'ui:click',
      ref: 'book',
      do: [
        {
          call: 'book',
          onSuccess: [{ set: 'booked', value: true }],
          onError: [
            { set: 'problem', value: '{{@error.message}}' },
            { set: 'status', value: '{{@error.status}}' },
          ],
        },
      ],
    },
  ],
}
Running herepress it
What its endpoints are answered
{
  POST /examples/endpoint-error/bookings: {
    status: 409,
    body: { message: 'That seat has just been taken.' },
  },
}
What is done to it
press book
What it sent
[
  {
    method: 'POST',
    url: '/examples/endpoint-error/bookings',
  },
]
What it then holds
{
  booked: false,
  problem: 'That seat has just been taken.',
  status: 409,
}
What it then says
409: That seat has just been taken.
Book seat C4
Output matches the expected value

Left: the action as the package ships it. Right: the same action running in this page, rendered with this site’s components. Below: the action run as the example specifies, on the installed package.