Socket
Socket
Sign inDemoInstall

@agape/exception

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @agape/exception

Error with status code


Version published
Weekly downloads
1
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Agape Exception

Errors with status codes

Synopsis


import { Exception } from '@agape/exception'

throw new Exception(404)

throw new Exception(404, "Could not find record with id " + id)

throw new Exception("Something bad happened")

throw new Exception(400, "Something bad happened")

Class

Exception

Properties

status

Number that corresponds with HTTP Error Codes

statusText

Accompanying text for the status code

message

A user friendly error message

The Constructor

The constructor in it's various forms is built to do what I mean; accepting either a status code, a message, or both as parameters. The three argument form allows setting a custom statusText.

Setting just the status code results in an exception where the message and statusText are populated automatically.

const e = new Exception(500)
e.status      /* 500 */
e.statusText  /* Internal Server Error */
e.message     /* Internal Server Error */ 

Setting just the message results in a 400 Bad Request error.

const e = new Exception("Invalid data")
e.status      /* 400 */
e.statusText  /* Bad Request */
e.message     /* Invalid data */ 

The statusText can be set in the three argument form.

const e = new Exception(404, "Silly Not Found", "Oops, couldn't find that")
e.status      /* 404 */
e.statusText  /* Silly Not Found */
e.message     /* Oops, couldn't find that */ 

Author

Maverik Minett maverik.minett@gmail.com

© 2023 Maverik Minett

License

MIT

Keywords

FAQs

Last updated on 26 Aug 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc