import { toErrorResponse } from "https://deno.land/x/netzo@0.4.11/database/plugin.ts";
Returns the converted HTTP error response from the given error. If the error
is an instance of Deno.errors.NotFound
, a HTTP 404 Not Found
error response is returned. This is done to translate errors thrown from
logic that's separated by concerns.
If the error is a HTTP-flavored error, the corresponding HTTP error response is returned.
If the error is a generic error, a HTTP 500 Internal Server error response is returned.
Examples
Example 1
Example 1
import { toErrorResponse } from "@/plugins/error_handling.ts";
import { errors } from "../deps/std/http/http_errors.ts";
const resp = toErrorResponse(new errors.NotFound("User not found"));
resp.status; // Returns 404
await resp.text(); // Returns "User not found"