Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/hono/mod.ts>HTTPException

Web Framework built on Web Standards
Extremely Popular
Go to Latest
class HTTPException
extends Error
import { HTTPException } from "https://deno.land/x/hono@v4.2.8/mod.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