@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
try {
await fetch(url);
} catch (err) {
throw wrapNetworkError(err, { operation: 'OAuth token request', host: 'account.demandware.com' });
}