Some error and logs handling utilities
const { Logger, LoggedError } = require('@soinlabs/hawk')
const LoggingLevels = {
error: Logger.ERROR,
warn: Logger.WARN,
info: Logger.INFO,
http: Logger.HTTP,
verbose: Logger.VERBOSE,
debug: Logger.DEBUG,
silly: Logger.SILLY,
};
const ErrorLevels = {
low: LoggedError.LOW_LEVEL,
medium: LoggedError.MEDIUM_LEVEL,
high: LoggedError.HIGH_LEVEL,
};
function sendError(message, status, errorLevel = ErrorLevels.low) {
const error = customizedHawk.CreateElasticError(message, status);
error.setErrorLevel(errorLevel);
customizedHawk.log(error, LoggingLevels.error);
throw error;
}
function sendWarning(msg) {
customizedHawk.log(
{ message: msg, referenceCode: customizedHawk.getReferenceCode() },
LoggingLevels.warn
)
}
function logError(message, code, errorLevel = ErrorLevels.low) {
const error = customizedHawk.CreateElasticError(message, code)
customizedHawk.log(error, LoggingLevels.error)
}
...
sendError("No id provided", 400);
sendWarning('Bad request')