FreightCake

Handle API Errors

Parse FreightCake API errors and decide when to correct, retry, or escalate a request.

FreightCake returns one JSON error envelope for every API-key endpoint.

Error Envelope

{
  "error": {
    "type": "invalid_request_error",
    "code": "parameter_invalid",
    "message": "Weight must be greater than zero",
    "param": "items.0.weight",
    "doc_url": "https://docs.freightcake.com/docs/errors"
  }
}
FieldTypeDescription
typestringStable error category for programmatic handling
codestringOptional machine-readable reason
messagestringHuman-readable explanation
paramstringOptional request field that failed validation
doc_urlstringOptional link to relevant documentation

HTTP Statuses

StatusTypeAction
400invalid_request_errorCorrect the request before retrying
401authentication_errorReplace or reactivate the API key
403permission_errorAdd the required key permission
404invalid_request_errorVerify the resource ID and key mode
409idempotency_errorReuse the original payload or choose a new idempotency key
422invalid_request_errorCorrect a semantically invalid field or state transition
429rate_limit_errorWait for Retry-After, then retry with backoff
500api_errorRetry an idempotent request with exponential backoff

TypeScript

import { AuthenticationError, RateLimitError, ValidationError } from '@freightcake/sdk'

try {
  await freightcake.quotes.create(input)
} catch (error) {
  if (error instanceof ValidationError) {
    console.error(error.param, error.message)
  } else if (error instanceof RateLimitError) {
    console.error('Retry after', error.retryAfter)
  } else if (error instanceof AuthenticationError) {
    console.error('Replace the API key')
  } else {
    throw error
  }
}

On this page