---
title: 404 Reasons Third-Party APIs Can't Get Their Errors Straight (And How to Fix It)
slug: 404-reasons-third-party-apis-cant-get-their-errors-straight-and-how-to-fix-it
date: 2026-03-04
author: Uday Gajavalli
categories: [Engineering]
excerpt: "Third-party API errors are wildly inconsistent. Learn how to normalize 200 OK errors, missing rate limit headers, and HTML responses without writing code."
tldr: API error normalization translates provider-specific errors into standard HTTP semantics. Truto uses declarative JSONata expressions to handle edge cases without hardcoded adapter logic.
canonical: https://truto.one/blog/404-reasons-third-party-apis-cant-get-their-errors-straight-and-how-to-fix-it/
---

# 404 Reasons Third-Party APIs Can't Get Their Errors Straight (And How to Fix It)


If you have built B2B SaaS integrations, you know the sinking feeling of debugging a silent failure, only to discover a third-party API returned a `200 OK` with an error message buried deep inside a JSON payload. 

**API error normalization** is the process of translating disparate, provider-specific error responses into standardized HTTP semantics. It allows your application to handle a Slack authentication failure, a Salesforce rate limit, and a GraphQL partial failure using the exact same logic, eliminating the need for integration-specific error handling code.

When you integrate with dozens of SaaS platforms, you quickly realize that software vendors fundamentally disagree on how HTTP works. Your codebase ends up absorbing this domain complexity, turning your engineering team into an expensive API maintenance crew. 

## Why Standardizing API Errors is a Nightmare

**The reality of third-party APIs is that error formats are wildly inconsistent.** Building a reliable integration means handling edge cases that directly violate standard HTTP conventions. 

Here are the most common API error anti-patterns developers face:

*   **The 200 OK Error Trap:** [GraphQL APIs](https://truto.one/blog/converting-graphql-to-rest-apis-a-deep-dive-into-trutos-proxy-architecture/) are notorious for this. Even when a query fails entirely, GraphQL endpoints almost always return a `200 OK` status. The actual error is hidden inside an `errors` array in the response body. Standard monitoring tools that watch for 5xx responses are completely blind to these failures. Slack does something similar, returning `200 OK` with `{ "ok": false, "error": "invalid_auth" }`.
*   **Semantically Incorrect Status Codes:** Freshdesk returns a `429 Too Many Requests` when a customer's subscription plan doesn't include API access. A real rate limit returns a `429` *with* a `Retry-After` header. Without that header, the error actually means `402 Payment Required`, but the API forces you to guess.
*   **Enterprise Authentication Edge Cases:** Salesforce REST APIs will throw `401 Unauthorized` for expired tokens and `403 Forbidden` for missing permissions. Add in their strict daily API limits, and your integration requires sophisticated exponential backoff and proactive token refresh logic just to stay alive.
*   **Non-JSON Responses:** When legacy APIs fail catastrophically, they often abandon JSON entirely, returning plain text or HTML error pages that break standard JSON parsers.

## The Brute Force Approach (And Why It Fails)

Most engineering teams try to solve this with the [Adapter Pattern](https://truto.one/blog/look-ma-no-code-why-trutos-zero-code-architecture-wins/). You write a specific error handler for HubSpot, another for Salesforce, and another for Zendesk.

```typescript
// The "Brute Force" Adapter Pattern
if (provider === 'slack' && response.data.ok === false) {
  throw new AuthError(response.data.error);
} else if (provider === 'freshdesk' && response.status === 429) {
  if (!response.headers.get('retry-after')) {
    throw new PaymentRequiredError('API access not available on this plan');
  }
}
```

This scales linearly with pain. You are hardcoding vendor quirks into your core business logic. Industry data shows that maintaining a single custom API integration costs engineering teams [between $50,000 and $150,000 annually](https://truto.one/blog/build-vs-buy-the-true-cost-of-building-saas-integrations-in-house/). When you multiply that by 50 integrations, the maintenance burden cripples your product roadmap. 

Traditional unified APIs suffer from the exact same problem behind the scenes. They maintain massive `if/else` blocks for every provider, which is why [schema normalization is the hardest problem in SaaS integrations](https://truto.one/blog/why-schema-normalization-is-the-hardest-problem-in-saas-integrations/).

## Truto's Solution: JSONata Error Expressions

At Truto, we refuse to write integration-specific code. Our entire platform uses a [programmable integration layer](https://truto.one/blog/your-unified-apis-are-lying-to-you-the-hidden-cost-of-rigid-schemas/) based on the Interpreter Pattern. [Zero-code architecture](https://truto.one/blog/look-ma-no-code-why-trutos-zero-code-architecture-wins/) is the only way to scale B2B integrations reliably.

Instead of writing `if/else` blocks, Truto uses **error expressions** - declarative JSONata strings stored directly in the integration's configuration. 

When a third-party API responds, the expression evaluates the raw response (status, headers, and body) and maps it to a structured object containing the correct HTTP status and a human-readable message. 

> [!NOTE]
> **What is an Error Expression?**
> A JSONata expression configured per-integration that evaluates a third-party API response and produces a standardized `ErrorExpressionResult` object. This normalizes wildly different vendor errors into predictable HTTP semantics before they reach your application.

The expression must evaluate to a strict schema:

```typescript
type ErrorExpressionResult = {
  status: number;          // Standard HTTP status code (e.g., 401, 403, 429)
  message: string;         // Human-readable error message
  headers?: Record<string, string>; // Optional normalized headers
  result?: any;            // Used to rewrite the response body if needed
}
```

## Real-World Error Normalization Patterns

Let's look at how this declarative approach handles the worst API offenders without a single line of application code.

### Pattern 1: Body-Based Errors (The 200 OK Problem)

For APIs like Slack or GraphQL that return `200 OK` for failures, we use JSONata to inspect the body and map the internal error code to a proper HTTP status.

Here is the actual error expression used for Slack:

```jsonata
$not(data.ok) ? {
  "status": $mapValues(data.error, {
    "invalid_auth": 401,
    "missing_scope": 403,
    "ratelimited": 429,
    "internal_error": 500
  }),
  "message": data.error
}
```

If `data.ok` is true, the expression falls through, and the system treats it as a success. If false, it intercepts the `200 OK` and rewrites it into a proper `401` or `429` error before it ever reaches your application.

### Pattern 2: Status Code Remapping

When HighLevel returns a `401` for a scope-based authorization failure, it triggers the wrong internal logic (authentication vs. authorization). We remap it to a `403`:

```jsonata
status = 401 and $contains(data.message, "not authorized for this scope") ? {
  "status": 403,
  "message": data.message
}
```

For the Freshdesk plan-limit issue mentioned earlier, the expression detects the absence of the `retry-after` header and corrects the status code:

```jsonata
status = 429 and $not($exists(headers.`retry-after`)) ? {
  "status": 402,
  "message": "API access is not available on this plan."
}
```

### Pattern 3: String and HTML Responses

Sometimes APIs fail so badly they return plain text. The expression checks the `$type()` of the data and matches a regular expression to extract meaning from the chaos. 

Here is how we handle Xero's plain-text permission errors:

```jsonata
$type(data) = "string" and $match(data, /You don't have permission to access/i) ? {
  "status": 403,
  "message": "Authorization error: Missing required permissions."
}
```

## Unified Error Code Reference

Once the expressions have done their work, every integration surfaces errors using the same HTTP semantics. Here's the standard mapping and what your client should do when it encounters each code:

| Status | Meaning | Category | Recommended Client Behavior |
|--------|---------|----------|-----------------------------|
| `400` | Bad Request - invalid payload, malformed query, or missing required field | Permanent | Fix the request. Do not retry. Surface validation errors to the user. |
| `401` | Unauthorized - token expired, revoked, or invalid | Requires user action | Trigger reconnect flow. Truto fires an `integrated_account:authentication_error` webhook automatically. |
| `402` | Payment Required - the customer's plan doesn't include API access | Permanent | Notify the user. No amount of retrying will help. |
| `403` | Forbidden - authenticated, but missing scope or permission | Requires user action | Check `truto_error_insight` for the specific missing scope. Prompt the user to grant additional permissions. |
| `404` | Not Found - resource doesn't exist or was deleted upstream | Permanent | Remove the record from your local cache. Do not retry. |
| `409` | Conflict - version mismatch, duplicate key, or concurrent update | Sometimes transient | Refetch and reconcile. Retry with fresh state at most once. |
| `422` | Unprocessable Entity - semantic validation failure | Permanent | Fix the payload. Surface field-level errors from the response body. |
| `429` | Rate Limited | Transient | Read `Retry-After`, back off, then retry. Truto standardizes this header across every integration. |
| `500` | Internal Server Error | Transient | Retry with exponential backoff (start at 1s, cap at 60s, jitter enabled). Give up after 5 attempts. |
| `502` / `503` / `504` | Bad Gateway / Service Unavailable / Gateway Timeout | Transient | Same as 500 - retry with backoff. Usually resolves within a minute. |

Every error originating from a third-party API is flagged with `truto_is_remote_error: true`, so you can distinguish provider failures from Truto platform errors in your logs.

## Retry and Backoff Recommendations Per Code

Not every error deserves the same treatment. Here's a policy that works across every integration on the platform:

| Error Class | Retry? | Strategy | Max Attempts |
|-------------|--------|----------|--------------|
| `429 Rate Limited` | Yes | Honor `Retry-After` exactly. Never retry sooner. | Unlimited (queue-based) |
| `5xx Server Errors` | Yes | Exponential backoff with jitter: `min(60s, 2^n * 1s) ± 20%` | 5 |
| `408 Request Timeout` | Yes | Same as 5xx | 3 |
| `401 Unauthorized` | No | Truto handles token refresh automatically. If a 401 still surfaces, the user must reconnect. | 0 |
| `403 Forbidden` | No | The token is valid but lacks scope. Retrying will not grant permissions. | 0 |
| `4xx (other)` | No | Client errors indicate a bug or bad input. Fix the request instead. | 0 |

Because Truto normalizes rate limit metadata into `ratelimit-limit`, `ratelimit-remaining`, `ratelimit-reset`, and `Retry-After` on both error *and* success responses, you can implement a single client-side backoff policy that works for HubSpot, Salesforce, Shopify, and every other provider without special casing.

## Transient vs Permanent: A Practical Example

Here's what a resilient client looks like on top of a normalized error surface:

```typescript
async function callTruto(request) {
  for (let attempt = 0; attempt < 5; attempt++) {
    const res = await fetch(request);
    if (res.ok) return res.json();

    const status = res.status;

    // Permanent errors - fail fast, surface to user
    if ([400, 402, 404, 422].includes(status)) {
      throw new PermanentError(await res.json());
    }

    // Auth failure - Truto has already flagged the account for reauth
    if (status === 401) {
      throw new ReauthRequiredError('User must reconnect this account');
    }

    // Missing scope - surface the specific permission to the user
    if (status === 403) {
      const body = await res.json();
      throw new ScopeError(body.truto_error_insight);
    }

    // Transient: rate limit - honor Retry-After exactly
    if (status === 429) {
      const retryAfter = parseInt(res.headers.get('retry-after') || '5');
      await sleep(retryAfter * 1000);
      continue;
    }

    // Transient: server errors - exponential backoff with jitter
    if (status >= 500) {
      const backoff = Math.min(60000, (2 ** attempt) * 1000);
      const jitter = backoff * 0.2 * Math.random();
      await sleep(backoff + jitter);
      continue;
    }

    throw new Error(`Unexpected status ${status}`);
  }
  throw new Error('Retry budget exhausted');
}
```

This loop works identically whether the underlying API is Salesforce's REST endpoint, Zendesk's Tickets API, or Slack's Web API. The complexity of each vendor's error format lives in a JSONata string, not in your client.

### Synchronous vs Webhook Error Surfaces

Truto surfaces errors through two channels:

*   **Synchronous API calls**: The normalized status code is returned on the HTTP response with a JSON body containing `message`, `metadata`, and `raw_response` (the original vendor payload, so you can still debug the underlying provider). This is what the retry loop above catches.
*   **Webhooks**: For asynchronous flows like sync jobs and background token refresh, errors are delivered as webhook events. A `sync_job_run:record_error` event fires per failed record when a sync encounters a transient failure. An `integrated_account:authentication_error` event fires the moment a 401 is detected from any third party, giving you a single hook to trigger reconnect UI regardless of which provider revoked the token.

## Mapping Examples: Salesforce and Zendesk

To show what "50 APIs, one contract" actually looks like, here are the error expressions used for two very different providers.

### Salesforce

Salesforce mostly uses standard HTTP codes, but it returns `REQUEST_LIMIT_EXCEEDED` in a JSON error body when you hit the daily API cap - often with an inconsistent status code. The expression targets that specific case and forces a proper 429:

```jsonata
$exists(data.errorCode) and data.errorCode = "REQUEST_LIMIT_EXCEEDED" ? {
  "status": 429,
  "message": data.message
}
```

Once this fires, Truto's rate limit path kicks in: the client sees a standard 429 with a `Retry-After` header, and every downstream consumer treats it like any other rate limit event.

### Zendesk

Zendesk returns fairly standard HTTP codes, but wraps error details in a nested structure with field-level validation. For providers like this, Truto's built-in fallback expression searches common message paths (`message`, `errors`, `error_message`, `detail`, `description`) across any nesting level - no custom expression required. When you need more structure, the pattern generalizes:

```jsonata
$exists(data.details) ? {
  "status": status,
  "message": data.error & ": " & data.description,
  "metadata": { "field_errors": data.details }
}
```

The `metadata` field preserves structured validation errors so your UI can highlight specific fields, while the top-level `message` remains a clean human-readable string.

## Pagination Normalization Comes Along for the Ride

Error handling is only half the problem. Anyone shopping for something that "normalizes pagination and error handling across 50 different APIs" is really asking for one thing: an integration layer that turns vendor chaos into a single contract. Truto applies the same declarative approach to pagination, covering the six formats you'll find in the wild:

*   **Cursor** - `after=xyz` tokens (HubSpot, most modern REST APIs)
*   **Page number** - `page=3&page_size=50` (classic pagination)
*   **Offset/limit** - `offset=100&limit=50` (SQL-style)
*   **Link header** - RFC 5988 `Link: <...>; rel="next"` (GitHub-style)
*   **Range** - HTTP Range headers for record ranges
*   **Dynamic** - JSONata-driven pagination for exotic schemes

Every unified list response returns the same shape - `{ result, next_cursor, prev_cursor, result_count }` - regardless of which format the upstream API uses. Your client iterates one way. The pagination strategy is configuration, not code.

## How Normalized Errors Power Self-Healing Integrations

Standardizing errors isn't just about clean server logs; it is the foundation of a resilient integration architecture. When every API error looks the same, you can build automated, self-healing systems on top of them.

### Reauth Detection

When an error expression evaluates to a `401`, Truto flags the resulting exception with a `truto_is_remote_error: true` property. This distinguishes a third-party authentication failure from a local one. 

Truto proactively refreshes OAuth tokens *before* they expire. But if a token is manually revoked by the user, the API will return a 401. The system intercepts this remote error flag, pauses any active sync jobs, marks the account as needing re-authentication, and fires a webhook. Instead of blindly retrying a dead token, it cleanly halts operations so you can prompt the user to reconnect.

### Standardized Rate Limiting

Rate limit implementations vary wildly. Freshdesk might use one format, while Shopify uses another. Alongside error expressions, Truto uses a separate `Rate Limit Expressions` configuration block with three dedicated JSONata expressions:

*   **`is_rate_limited`**: Evaluates the response to determine if a limit was hit. If an API returns a `200 OK` with a custom rate limit header, this expression catches it and forces a standard `429 Too Many Requests` response.
*   **`retry_after_header_expression`**: Extracts the provider's specific retry logic (whether it's seconds or an HTTP-date) and normalizes it into a standard `Retry-After` header in seconds.
*   **`rate_limit_header_expression`**: Maps custom headers (like `X-RateLimit-Remaining`) into standard `ratelimit-limit`, `ratelimit-remaining`, and `ratelimit-reset` headers.

These standardized headers are attached to both 429 errors and successful 2xx responses, so clients can always track their quota. Your application only ever has to read `Retry-After` and the standard `ratelimit-*` headers to manage its queue, regardless of which CRM you are calling.

### Actionable Error Insights

When a `403 Forbidden` is normalized, Truto automatically generates an error insight. The system compares the required OAuth scopes against the granted scopes stored in the account context, instantly diagnosing permission mismatches. Instead of a generic "Access Denied," you get exactly which scope is missing.

## Stop Writing Error Handlers

Every hour your engineers spend writing try/catch blocks for undocumented API errors is an hour they aren't building your core product. Third-party APIs will always have quirks, edge cases, and flat-out broken implementations. Your codebase shouldn't have to absorb them.

By treating error normalization as configuration rather than code, you decouple your application from vendor instability. 

> Stop wrestling with 50 different API error formats. See how Truto's declarative architecture can standardize your integrations in minutes.
>
> [Talk to us](https://truto.one/book-a-demo/)
