Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/netzo/core/plugins/api/mod.ts>toErrorResponse

Deno-powered framework for building business web apps
Go to Latest
function toErrorResponse
import { toErrorResponse } from "https://deno.land/x/netzo@0.3.91/core/plugins/api/mod.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

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"

Parameters

error: any