NetworkErrorclass
new NetworkError(message?: string, options: BaseErrorOptions = {})| Param | Type | |
|---|---|---|
message | string | Optional human-readable description of the network problem. |
options | BaseErrorOptions | Options for BaseError that provide additional helpful error functionality. Defaults to {} |
.caller | AnyCaller | Modify the stack to trim off lines after a certain calling function. |
| Return | |
|---|---|
NetworkError | Thrown in the event of network issues e.g. the user's internet connection is down, or the server is down. |
Thrown in the event of network issues e.g. the user's internet connection is down, or the server is down.
Thrown on a network-level failure — a connection refused, a server unreachable, a request that never completed. Use it for transport problems, as distinct from a response that arrived but indicated an error (ResponseError).
Usage
import { NetworkError } from "shelving/error";
async function fetchData(url: string): Promise<Response> {
try {
return await fetch(url);
} catch {
throw new NetworkError("Could not reach server");
}
}See shelving/error for shared behaviour — attaching context fields, caller trimming, and catching by type.
Examples
throw new NetworkError("Connection lost");