@krypton-org/krypton-auth
Version:
Express authentication middleware, using GraphQL and JSON Web Tokens.
25 lines • 916 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ErrorTypes_1 = __importDefault(require("./ErrorTypes"));
/**
* Express middleware rendering {@link module:error/ErrorTypes.OperationalError} error message to client, avoiding server crash for those king of error.
* @param {Error} err
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @renders JSON object containing the error to display.
*/
exports.default = (err, req, res, next) => {
const notifications = [];
if (err instanceof ErrorTypes_1.default) {
notifications.push({ type: err.type, message: err.message });
res.json({ notifications });
}
else {
next(err);
}
};
//# sourceMappingURL=ErrorHandler.js.map