Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

adonisjs/adonis-generic-exceptions

AdonisJs Generic Exceptions 🚀

Customized exceptions for AdonisJs

NPM Version

This repo contains some helpful classes to throw uniform exceptions through out the application. Ofcourse you can throw exceptions using new Error() but using this package will help in throwing informative exceptions.

Setup

Install package using npm.

npm i @adonisjs/generic-exceptions

Usage

The package exports all exceptions from node-exceptions and adds additional methods to the RuntimeException class.

const { InvalidArgumentException } = require('@adonisjs/generic-exceptions')

const message = 'Model.create requires an object'
const status = 400
const code = 'E_INVALID_ARGUMENT'

throw new InvalidArgumentException(message, status, code)

The status must be a valid HTTP status code and code is a unique error code to recognize an exception. AdonisJs error codes starts with E_, for example: E_MISSING_CONFIG.

RuntimeException

The following static methods are added to the runtime exception to make the adonisJs related exceptions consistent.

missingConfig(key, file)

missingAppKey(providerName)

incompleteConfig(missingKeys, file)

invoke(message, status, [code])

Checkout the complete API docs here

About

A module with all generic exceptions other modules can use

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 3

  •  
  •  
  •