Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
node-exceptions
Advanced tools
Throwing errors in Javascript does not give much information about the error type as it is really hard to throw custom exceptions. Node Exceptions is a tiny wrapper which will let you extend the Error class and throw custom errors.
Errors are thrown anywhere inside the code and handling them properly is required. For example you have an HTTP application, which can throw multiple errors and in order to handle those errors gracefully, you need to know the error types or their names.
switch (err.name) {
case 'HttpException':
// do something
case 'RunTimeException':
// do something else
}
npm i --save node-exceptions
const NE = require('node-exceptions')
class MyCustomError extends NE.LogicalException {}
try {
throw new MyCustomError('Something bad happened')
} catch (e) {
console.log(e.status) // equals 500
console.log(e.name) // equals MyCustomError
console.log(e.message) // Something bad happened
console.log(e.stack) // Error stack with correct reference to filepath and linenum
console.log(e.toString()) // MyCustomError: Something bad happened
}
It is also possible to have a custom error status when throwing exceptions.
const NE = require('node-exceptions')
class HttpException extends NE.LogicalException {}
try {
throw new HttpException('Page not found', 404)
} catch (e) {
console.log(e.status) // equals 404
}
Access complete API Docs here
4.0.1 (2018-10-20)
<a name="4.0.0"></a>
<a name="3.0.0"></a>
FAQs
Extendable error class for nodejs to extend native errors
The npm package node-exceptions receives a total of 19,104 weekly downloads. As such, node-exceptions popularity was classified as popular.
We found that node-exceptions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.