Conflict class represents an HTTP error response with status code 409. It is used to standardize "Conflict" error responses, typically when a request conflicts with the current state of a resource.ts
import { Conflict } from "@arkyn/server/conflict";
message (required): A descriptive message explaining the conflict cause.cause (optional): Additional information about the conflict 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 { Conflict } from "@arkyn/server/conflict";// Basic usage - throw the errorthrow new Conflict("Email already registered");// With cause informationthrow new Conflict("Resource version mismatch", {currentVersion: 5,requestedVersion: 3,});// Convert to Response objectconst error = new Conflict("Username already taken");return error.toResponse();// Using toJson alternativereturn error.toJson();
json
{"name": "Conflict","message": "Email already registered"}
409, set on the Response object itself, the status code is not part of the JSON body.cause is passed to the constructor, it is included in the body as well:json
{"name": "Conflict","message": "Resource version mismatch","cause": "{\"currentVersion\":5,\"requestedVersion\":3}"}
cause parameter, when provided, is serialized with JSON.stringify() and included in the response body under the cause key, it is sent to clients, not just kept for server-side debugging. Because it's stringified, cause appears in the JSON body as a JSON-encoded string rather than a nested object.