ResponseErrorclass
new ResponseError(message?: string, { code = 400, ...options }: ResponseErrorOptions = {})| Param | Type | |
|---|---|---|
message | string | Optional human-readable description of why the response was rejected. |
options | ResponseErrorOptions | Optional options — code sets the HTTP status (defaults to 400); caller and contextual fields are applied via setBaseErrorOptions(). Defaults to {} |
| Return | |
|---|---|
ResponseError | Error thrown when a received HTTP response isn't OK. |
| Property | Type | |
|---|---|---|
.code | number | HTTP status code for the response. required readonly |
Error thrown when a received HTTP response isn't OK.
- Carries the response's HTTP status
code(defaults to400).
Thrown when a received response indicates an error — the HTTP 4xx/5xx range. Its .code property defaults to 400. Use it for a response that arrived but was unsuccessful, as distinct from a transport failure (NetworkError).
Usage
import { ResponseError } from "shelving/error";
function checkResponse(res: Response): void {
if (!res.ok) throw new ResponseError(res.statusText, { code: res.status });
}See shelving/error for shared behaviour — attaching context fields, caller trimming, and catching by type.
Examples
throw new ResponseError("Unexpected response body", { code: 422 });