Developer Preview — This project is in active development. APIs may change. Provide feedback
Skip to content

@salesforce/b2c-tooling-sdk / clients / getApiErrorMessage

Function: getApiErrorMessage()

getApiErrorMessage(error, response): string

Defined in: packages/b2c-tooling-sdk/src/clients/error-utils.ts:38

Extract a clean error message from an API error response.

Handles multiple API error patterns and falls back to HTTP status. This ensures that HTML response bodies (like error pages) are never included in user-facing error messages.

Supported error patterns:

  • ODS/SLAS: { error: { message: '...' } }
  • OCAPI: { fault: { message: '...' } }
  • SCAPI/Problem+JSON: { detail: '...', title: '...' }
  • Standard Error: { message: '...' }

Parameters

error

unknown

The error object from an API response

response

The HTTP response (for status code fallback)

Response | { status: number; statusText: string; }

Returns

string

A clean, human-readable error message

Example

typescript
const {data, error, response} = await client.GET('/sites', {...});
if (error) {
  const message = getApiErrorMessage(error, response);
  // Returns structured error message or "HTTP 521 Web Server Is Down"
}

Released under the Apache-2.0 License.