
Security News
Potemkin Understanding in LLMs: New Study Reveals Flaws in AI Benchmarks
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
n-custom-errors
Advanced tools
Custom errors for Node.js.
get<errorName>Error()
get<errorName>ErrorType()
is<errorName>Error()
# Add to project
$ npm i n-custom-errors
// Registering errors:
customErrors.registerError('AccessDenied', 403);
customErrors.registerError('DuplicateObject', 409);
customErrors.registerError('ObjectNotFound', 404, '${objectName} not found');
// Creating custom errors:
let objectNotFoundError = customErrors.getObjectNotFoundError({ objectName: 'user' });
let duplicateObjectError = customErrors.getDuplicateObjectError('The email is not unique');
console.log(objectNotFoundError);
/*
prints => {
name: 'ObjectNotFoundError',
message: 'user not found',
statusCode: 404
}*/
console.log(duplicateObjectError);
/*
prints => {
name: 'DuplicateObjectError',
message: 'The email is not unique',
statusCode: 409
}*/
// Checking that an error is a custom error:
let err = new Error();
let objectNotFoundError = customErrors.getObjectNotFoundError({ objectName: 'user' });
customErrors.isObjectNotFoundError(err)); // returns false
customErrors.isObjectNotFoundError(objectNotFoundError)); // returns true
registerError(name, statusCode, messageTemplate)
Registers a new custom error.
name
- error name, required, must be an unique. Name must be without Error
postfix.statusCode
- http status code for error.messageTemplate
- template for a message, must contains parameters in the following format: ${objectName} not found
. To pass the parameters to the template, parameters must be an object with defined properties: customErrors.getObjectNotFoundError({ objectName: 'user' })
. If parameters is a string, than this string will be used in an error message without template: customErrors.getObjectNotFoundError('User with a name user1 not found, please use another filter')
.isKnownError(err)
Returns true
if err
is a registered custom error, false
otherwise.
err
- error object, required.get<errorName>Error(msg)
This function is added automatically when a new custom error is registered.
Creates a custom error with message msg
, it can be the parameters object if an error is registered with messageTemplate
.
msg
- an error message, required.get<errorName>ErrorType()
This function is added automatically when a new custom error is registered.
Gets a custom error type.
is<errorName>Error(err)
This function is added automatically when a new custom error is registered.
Returns true
if err
is a custom error, false
otherwise.
err
- error object, required.Alexander Mac
Licensed under the MIT license.
FAQs
Custom errors for Node.js
The npm package n-custom-errors receives a total of 11 weekly downloads. As such, n-custom-errors popularity was classified as not popular.
We found that n-custom-errors 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
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.