ServerError class represents an HTTP error response with status code 500. It is used to standardize "Internal Server Error" responses, typically when an unexpected error occurs on the server side.ts
import { ServerError } from "@arkyn/server";
message (required): A descriptive message explaining the server 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 { ServerError } from "@arkyn/server";// Basic usage - throw the errorthrow new ServerError("An unexpected error occurred");// With cause informationthrow new ServerError("Database operation failed", {operation: "insert",table: "users",originalError: "Connection lost",});// Convert to Response objectconst error = new ServerError("Failed to process request");return error.toResponse();// Using toJson alternativereturn error.toJson();
json
{"ok": false,"status": 500,"message": "An unexpected error occurred"}
cause parameter is serialized to JSON and stored for debugging purposes but is not included in the response body sent to clients.