Error Handling
Every VeloraClient method throws a VeloraError when the server responds with a non-2xx status. VeloraError extends Error and carries the HTTP status code and the parsed response body.
VeloraError#
Class definition
class VeloraError extends Error {
/** HTTP status code, e.g. 400, 401, 403, 404, 500 */
status: number
/** Parsed server response body */
body: {
error?: string // machine-readable error key
msg?: string // human-readable message
[key: string]: any
} | null
}Basic catch#
ts
import { VeloraClient, VeloraError } from '@rimora/velora'
import fetch from 'node-fetch'
const client = new VeloraClient({
apiKey: process.env.VELORA_API_KEY,
fetch: fetch as any
})
try {
const job = await client.getJob('non-existent-id')
} catch (err) {
if (err instanceof VeloraError) {
console.error('API error', err.status, err.body?.error, err.body?.msg)
} else {
throw err // re-throw unexpected errors
}
}Switch on status#
ts
import { VeloraError } from '@rimora/velora'
try {
await client.createJob({ ... })
} catch (err) {
if (!(err instanceof VeloraError)) throw err
switch (err.status) {
case 400:
console.error('Validation error:', err.body?.msg)
break
case 401:
console.error('Auth failed — check your API key')
break
case 403:
if (err.body?.error === 'insufficient_scope') {
console.error('API key is missing required scope:', err.body?.msg)
} else if (err.body?.error === 'job_limit_exceeded') {
console.error('Plan job limit reached — upgrade your subscription')
}
break
case 404:
console.error('Job not found')
break
default:
console.error('Unexpected error:', err.status, err.body)
}
}Common error codes#
| Status | error key | Cause |
|---|---|---|
400 | validation_error | Required field missing, invalid cron expression, or blocked target URL |
401 | api_key_missing | Authorization header absent or malformed |
401 | invalid_api_key | Key not found or revoked |
403 | insufficient_scope | Key lacks the required scope for this action |
403 | job_limit_exceeded | Plan job limit reached |
404 | not_found | Resource does not exist or belongs to another account |
500 | db_error | Temporary database error — safe to retry |
Network errors#
If the fetch itself fails (DNS, TLS, timeout), the underlying fetch error is thrown directly — it will not be a VeloraError. Catch Error instances separately and inspect err.message.
ts
try {
await client.listJobs()
} catch (err) {
if (err instanceof VeloraError) {
// server replied with non-2xx
} else if (err instanceof Error) {
// network-level: DNS, TLS, timeout
console.error('Network error:', err.message)
}
}Node.js TLS errors (e.g.
ERR_MODULE_NOT_FOUND, tlsv1 unrecognized name) are network-level and indicate a TLS SNI mismatch. Pass a custom https.Agent with servername set — see the Configuration guide.