Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gtramontina.com/elysia-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gtramontina.com/elysia-error-handler

Elysia plugin to define HTTP error handlers in a more declarative way.

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
28
increased by1300%
Maintainers
1
Weekly downloads
 
Created
Source

Elysia Error Handler

Elysia plugin to define HTTP error handlers in a more declarative way.

Installation

bun add --exact @gtramontina.com/elysia-error-handler

Usage

import { errorHandler } from "@gtramontina.com/elysia-error-handler";
import { Elysia } from "elysia";

class CustomForbiddenError extends Error { status = 403 }

new Elysia()
	.use(
		errorHandler({
			400: () => new Response("too bad!", { status: 400 }), // return Response
			403: () => 403,                                       // return number
			404: () => "uh-oh! not found!",                       // return string
			500: ({ error }) => `error: ${error.message}`,        // access to context
		}),
	)
	.get("/400", () => { throw new ParseError(); })
	.get("/403", () => { throw new CustomForbiddenError(); })
	.get("/404", () => { throw new NotFoundError(); })
	.get("/500", () => { throw new Error("boom!"); })
	.listen(3000);

You can also import…

import { ErrorStatus } from "@gtramontina.com/elysia-error-handler";

…for more descriptive error status names, such as ErrorStatus.BadRequest, ErrorStatus.TooManyRequests, and so on.

FAQs

Package last updated on 11 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc