{
  "id": 22785267,
  "title": "Handle API errors by code, not by message",
  "url": "https://urgent.news/2026/11/30/handle-api-errors-by-code-not-by-message",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-30T13:43:39.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/publora/handle-api-errors-by-code-not-by-message-fl7"
  },
  "original_language": null,
  "account": "Most API integrations currently handle errors by parsing the message contained within the response body. This approach can break if the message changes, even if the underlying error code remains the same. In contrast, Publora's API assigns stable error codes to each error that can be acted upon. These codes remain consistent even if the accompanying message changes.\n\nThe article suggests structuring error handling around these stable codes, which can appear in five different locations within an API response. A handler that only checks for the presence of an error message in the top-level response may miss errors that are nested within validation errors, warnings, or media results.\n\nKey examples include:\n\n1. Top-level codes on 4xx responses such as IDEMPOTENCY_KEY_CONFLICT, POST_NOT_EDITABLE, and plan limits.\n2. Validation errors in validation.errors[].code when a post fails platform-specific rules during scheduling.\n3. Warnings[].code for successful responses that contain additional information the API wants the caller to be aware of.\n4. Per URL entries in mediaResults[] when attaching media by link.\n5. Per connection entries in issues[] on analytics routes.\n\nThe article provides a concrete example of a validation error encountered when attempting to schedule an Instagram post without an image. The API returned an HTTP 400 response containing detailed validation error information, including the specific code (MEDIA_REQUIRED), platform (instagram), and suggested action (ATTACH_REQUIRED_MEDIA). This level of granularity allows developers to precisely identify and address the issue.\n\nThe article outlines three main categories for handling these error codes:\n\n1. Action = 'fix-input': This covers all other validation errors where the issue lies with the input data provided by the caller. The system should inform the user of the problem and point them to the specific platform and field that needs to be corrected.\n\n2. Action = 'retry': Certain error codes, such as IDEMPOTENCY_IN_FLIGHT, MEDIA_URL_RATE_LIMITED, MEDIA_UPLOAD_PENDING, and MEDIA_VALIDATION_PENDING, indicate issues that can be resolved by retrying the identical request after the specified time, respecting any Retry-After headers. This approach ensures that retries do not create duplicate records.\n\n3. Action = 'reread-then-retry': Some error codes, like POST_GROUP_VERSION_CONFLICT and POST_PUBLISH_IN_PROGRESS, suggest that another user has modified the resource since the original request was made. In these cases, the system should fetch the updated resource using a GET request, update it accordingly, and then retry the original request.\n\nThe article emphasizes that 200 responses can still contain warnings[], which should be checked for existence before being parsed. For instance, if a scheduled time is adjusted due to clock skew, the API will return a SCHEDULED_TIME_COERCED warning alongside the successful response.\n\nThe full list of error codes, their locations within the response, retryability status, and recommended recovery actions is available in the API error code catalog. The author recommends keeping this catalog readily accessible for reference when implementing error handling logic in API integrations.",
  "summary": "The first version of most API integrations handles errors by reading the message: if (body.error.includes('character limit')) . It works until someone rewords the message. The Publora API gives every error you can act on a stable code . Messages may change; codes don't. Here is how I'd structure error handling around them, with real responses. Where codes show up A code can sit in five places,…",
  "summary_source": "publisher",
  "key_points": [
    "API errors handled by stable codes, not changing messages",
    "Error codes appear in five locations: top-level, validation, warnings, media results, issues",
    "Three handling categories: fix-input, retry, and reread-then-retry"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}