Refusal readers
The refusal readers take the error the client throws, or a JSON error body, and return the details your app acts on, such as which lines of a hold were short. Import them from @agentpost-tools/resourceshark-sdk. Use a reader when your code handles one of the codes in the table; for any other code, read the error’s own fields.
ResourcesharkApiError
The client throws ResourcesharkApiError when the API answers with an error. Read status, code, and, when present, errorClass, details, and docs. The client sets errorClass when the answer’s class is a recognized error class. It sets code to unknown when it cannot read a code and message from the error body. ResourceShark’s errors lists every code and class.
Checking code gives details its type. After error.code === 'insufficient_supply', error.details is { lines }, and after error.code === 'cursor_expired', it is { oldest, latest }. A code without one fixed shape, and every Platform code such as throttled, keeps details as unknown. ErrorDetails and ErrorDetailsOf name these types.
Use isErrorBody(value) to recognize ResourceShark’s standard error body, with a class and docs link.
Readers
Each reader accepts a ResourcesharkApiError or a JSON error body, and returns undefined when the matching details are absent.
| Reader | Refusal code | Result |
|---|---|---|
shortLines(error) |
insufficient_supply, exhausted_until_supply, assignment_infeasible |
The short lines, with their scopes as ResourceShark reports them. |
nextSupplyAt(error) |
exhausted_until_supply |
The earliest next supply time ResourceShark reports. |
expiredHold(error) |
hold_expired |
The hold ID, expiry, and any line availability ResourceShark answers with. |
resolvedHold(error) |
hold_resolved |
The hold’s first resolution. |