Skip to content
View as Markdown
View as Markdown

@salesforce/b2c-tooling-sdk / errors / wrapNetworkError

Function: wrapNetworkError()

wrapNetworkError(err, context): unknown

Defined in: packages/b2c-tooling-sdk/src/errors/network-error.ts:307

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' });
}

Released under the Apache-2.0 License.