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

[@salesforce/b2c-tooling-sdk](../../modules.md) / [errors](../index.md) / wrapNetworkError

# Function: wrapNetworkError()

> **wrapNetworkError**(`err`, `context`): `unknown`

Defined in: [packages/b2c-tooling-sdk/src/errors/network-error.ts:307](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/0c642abce71b645ae9df3c6046c2bf8396a2845c/packages/b2c-tooling-sdk/src/errors/network-error.ts#L307)

Wraps a network error with context about the failed operation and target host.

If the error is already a NetworkError, returns it as-is (possibly filling in missing context).
If the error is not a network error (e.g., HTTPError), returns it unchanged.
Otherwise, classifies and wraps the error in a NetworkError with an actionable message.

This function does NOT throw — it returns the wrapped or original error. The caller must throw it.

## Parameters

### err

`unknown`

The error to wrap

### context

Operation and host context for the error

#### host?

`string`

#### operation?

`string`

## Returns

`unknown`

The wrapped NetworkError, or the original error if it's not a network error

## Example

```ts
try {
  await fetch(url);
} catch (err) {
  throw wrapNetworkError(err, { operation: 'OAuth token request', host: 'account.demandware.com' });
}
```
