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.
{
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}}' },
],
},
],
},
],
}{
POST /examples/endpoint-error/bookings: {
status: 409,
body: { message: 'That seat has just been taken.' },
},
}press book
[
{
method: 'POST',
url: '/examples/endpoint-error/bookings',
},
]{
booked: false,
problem: 'That seat has just been taken.',
status: 409,
}409: That seat has just been taken. Book seat C4
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.