New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@poppinss/exception

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poppinss/exception

Utility to create custom exceptions

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24K
increased by11.99%
Maintainers
0
Weekly downloads
 
Created
Source

@poppinss/exception

Create custom exceptions with error code, status, and the help description.


gh-workflow-image npm-image license-image

Introduction

The @poppinss/exception package provides with a base Exception class that can be used to create custom errors with support for defining the error status, error code, and help description.

import { Exception } from '@poppinss/exception'

class ResourceNotFound extends Exception {
  static code = 'E_RESOURCE_NOT_FOUND'
  static status = 404
  static message = 'Unable to find resource'
}

throw new ResourceNotFound()

Anonymous error classes

You can also create an anonymous exception class using the createError method. The return value is a class constructor that accepts an array of values to use for message interpolation.

The interpolation of error message is performed using the util.format method.

import { createError } from '@poppinss/exception'

const E_RESOURCE_NOT_FOUND = createError<[number]>(
  'Unable to find resource with id %d',
  'E_RESOURCE_NOT_FOUND'
)

const id = 1
throw new E_RESOURCE_NOT_FOUND([id])

Contributing

One of the primary goals of poppinss is to have a vibrant community of users and contributors who believes in the principles of the framework.

We encourage you to read the contribution guide before contributing to the framework.

Code of Conduct

In order to ensure that the poppinss community is welcoming to all, please review and abide by the Code of Conduct.

License

Poppinss exception is open-sourced software licensed under the MIT license.

FAQs

Package last updated on 27 Dec 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