---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../modules.md) / [clients](../index.md) / throwOcapiError

# Function: throwOcapiError()

> **throwOcapiError**(`error`, `response`, `prefix`, `requiredScopes?`): `never`

Defined in: [packages/b2c-tooling-sdk/src/clients/error-utils.ts:179](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/error-utils.ts#L179)

Throws a well-formed Error for a failed OCAPI call.

Centralizes OCAPI-terminal error handling so every call site behaves
consistently:
- OCAPI deprecation faults become an [OcapiDeprecatedError](../classes/OcapiDeprecatedError.md) with
  actionable SCAPI-setup guidance, naming `requiredScopes` when the operation
  has a SCAPI equivalent.
- Everything else throws `Error(`${prefix}: ${message}`)` where `message`
  is the fault text from [getApiErrorMessage](getApiErrorMessage.md).

The original `error` is always attached as `cause` for debug logging.

## Parameters

### error

`unknown`

The error object from an openapi-fetch result.

### response

The HTTP response (for status fallback).

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

### prefix

`string`

Operation-specific prefix, e.g. `'Failed to list code versions'`.

### requiredScopes?

`string`[]

SCAPI scope(s) the equivalent operation needs, named
  in the deprecation message. Omit for OCAPI-only operations.

## Returns

`never`

## Throws

Always throws — return type is `never`.
