errorHandler function is a centralized utility for handling both success and error responses, converting them into standard HTTP Response objects. It serves as a unified response handler that simplifies API response management.ts
import { errorHandler } from "@arkyn/server";
error (required)anyResponsetypescript
import { errorHandler, Success, NotFound, Created } from "@arkyn/server";async function getUser(id: string) {try {const user = await findUser(id);if (!user) throw new NotFound("User not found");throw new Success("User found", user);} catch (error) {return errorHandler(error);}}
errorHandler function ensures consistent response formatting across your entire API, making it easier to maintain and debug.ServerError as additional context, which can be useful for logging and debugging.