Error handling
When building your Atmo app, handling errors returned from Runnables is pretty essential. When a Runnable returns an error, it contains a code and a message. The code must be a valid HTTP response status code. Using the Directive, you can manage how your application behaves when an error is returned:
The default behaviour for any error is for the handler to return.
Any time a Runnable returns an error, you can decide what to do with it using the onErr clause:
1
- type: request
2
resource: /repo/report/*repo
3
method: GET
4
steps:
5
- fn: check-cache
6
as: report
7
onErr:
8
any: continue
9
10
- fn: send-report
Copied!
In its basic form, onErr allows you to tell Atmo to ignore any error from a Runnable. When using continue, the JSON of the error will be placed into state, such as {"code":404,"message":"not found"}
To gain more control, you can choose what to do based on error codes:
1
- type: request
2
resource: /repo/report/*repo
3
method: GET
4
steps:
5
- fn: check-cache
6
as: report
7
onErr:
8
code:
9
404: continue
10
other: return
11
12
- fn: send-report
Copied!
Technically, any return (such as an 'any' or 'other') can be omitted since it is the default behaviour, but it can improve readability of your Directive when included.
When defining specific error codes, you cannot use 'any', use 'other' instead. If no specific codes are specified, use 'any'.
Whenever Atmo decides to return based on your Directive's instructions, the error's JSON is returned to the caller with the status code set to the error code.
Last modified 5mo ago
Export as PDF
Copy link