A utility npm package that parses error messages and extracts relevant information to generate a structured error object.
npm install krrs-error-code-parser
const errorCodeParser = require('error-code-parser');
const error = new Error('BAD_REQUEST Something not found');
const parsedError = errorCodeParser(error);
console.log(parsedError);
output: {
code: 400,
message: 'Something not found'
}
BAD_REQUEST, BAD_REQUEST_TO_IGNORE = 400 NOT_FOUND = 404 CONFLICT = 422 FORBIDDEN = 403 UNPROCESSABLE = 422 default = 500