Module

x/hono/http-exception.ts>HTTPException

Fast, Lightweight, Web-standards
Extremely Popular
Go to Latest
class HTTPException
extends Error
import { HTTPException } from "https://dotland.deno.dev/x/hono@v4.2.2/http-exception.ts";

HTTPException must be used when a fatal error such as authentication failure occurs.

Examples

Example 1

import { HTTPException } from 'hono/http-exception'

// ...

app.post('/auth', async (c, next) => {
  // authentication
  if (authorized === false) {
    throw new HTTPException(401, { message: 'Custom error message' })
  }
  await next()
})

Constructors

new
HTTPException(status?: StatusCode, options?: HTTPExceptionOptions)

Properties

readonly
optional
res: Response
readonly
status: StatusCode

Methods

getResponse(): Response