BadGateway class represents an HTTP error response with status code 502. It is used to standardize "Bad Gateway" error responses, typically when an upstream server returns an invalid response.ts
import { BadGateway } from "@arkyn/server";
message (required): A descriptive message explaining the error cause.cause (optional): Additional information about the error cause, which can be any serializable data.toResponse() - Converts the instance into a Response object with JSON body and Content-Type: application/json header.toJson() - Alternative method using Response.json() for generating the JSON error response.typescript
import { BadGateway } from "@arkyn/server";// Basic usage - throw the errorthrow new BadGateway("Payment gateway unavailable");// With cause informationthrow new BadGateway("External API failed", {service: "payment-provider",originalError: "Connection timeout",});// Convert to Response objectconst error = new BadGateway("Upstream server error");return error.toResponse();// Using toJson alternativereturn error.toJson();
json
{"ok": false,"status": 502,"message": "Payment gateway unavailable"}
cause parameter is serialized to JSON and stored for debugging purposes but is not included in the response body sent to clients.