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/errorHandler";
error (required)anyResponsetypescript
import { errorHandler } from "@arkyn/server/errorHandler";import { Success } from "@arkyn/server/success";import { NotFound } from "@arkyn/server/notFound";import { Created } from "@arkyn/server/created";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.