Docs · nexoflow-sdk Errors
nexoflow-sdk
Error handling
Every failed call throws a NexoFlowError, so you can branch on the HTTP status, a structured code or a few convenience flags.
Example
errors.ts
import { NexoFlow, NexoFlowError } from "nexoflow-sdk"
try {
const { data } = await nf.posts.get("nonexistent")
} catch (err) {
if (err instanceof NexoFlowError) {
console.log(err.status) // 404
console.log(err.code) // "HTTP_404"
console.log(err.message) // "Post not found."
console.log(err.traceId) // "nf_…", also sent as X-Request-Id
console.log(err.attempts) // 1 (404s aren't retried)
console.log(err.isNotFound) // true
console.log(err.isUnauthorized) // false
console.log(err.isRateLimited) // false
}
}Properties
| Property | What it tells you |
|---|---|
status | HTTP status (404, 401, 500…), or 0 when there was no answer (a network error or timeout) |
code | HTTP_ plus the status (the Content API sends no code of its own), or TIMEOUT / NETWORK_ERROR when the status is 0 |
message | The API's message, written to be read |
traceId | The SDK's id for the call, also sent as X-Request-Id, to match it in your own logs |
requestId, details | Filled only when an error body carries them; the Content API's errors don't |
attempts, elapsedMs | How many tries were made, and how long they took in all |
isNotFound, isUnauthorized, isRateLimited | Shortcuts for 404, 401 and 429 |
isTimeout | True when code is TIMEOUT: the client's time limit ran out, or the call was cancelled |
isNetworkError | True whenever status is 0, timeouts included |
Retries happen before the error is thrown: by default up to 3 attempts for network errors, timeouts, 5xx and 429 answers. See retries & timeouts.
What the API returns
| Status | When | Retried |
|---|---|---|
400 | A required parameter is missing | No |
401 | The key is missing, doesn't start with pk_live_, isn't recognised, or was sent in the URL | No |
402 | The business's plan has ended, and so have the 30 days its posts stay up afterwards | No |
404 | No published post with that slug, or the business was deleted | No |
500 | Something failed on NexoFlow's side | Yes |
The Content API reference lists the same statuses for plain HTTP.
Errors before a request
A few mistakes are caught before anything is sent, and throw a plain Error rather than a NexoFlowError: a missing key or one that doesn't start with pk_live_, a bad timeout or retry value in the constructor, and an empty slug passed to nf.posts.get.