1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Configure log levels for specific error types

This commit is contained in:
sarayourfriend 2024-03-29 17:40:49 +11:00
parent fae2980692
commit 5c8e01c034
No known key found for this signature in database
2 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import {Config} from '../common/config/private/Config';
import {LogLevel} from '../common/config/private/PrivateConfig';
import {ErrorCodes} from '../common/entities/Error';
const forcedDebug = process.env['NODE_ENV'] === 'debug';
@ -103,4 +104,25 @@ export class Logger {
});
console.log(date + tag + LOG_TAG, ...args);
}
public static logLevelForError(e: ErrorCodes): LoggerFunction {
switch (e) {
case ErrorCodes.INPUT_ERROR:
case ErrorCodes.NOT_AUTHENTICATED:
case ErrorCodes.ALREADY_AUTHENTICATED:
case ErrorCodes.NOT_AUTHORISED:
case ErrorCodes.PERMISSION_DENIED:
case ErrorCodes.CREDENTIAL_NOT_FOUND:
return Logger.debug
case ErrorCodes.SETTINGS_ERROR:
case ErrorCodes.TASK_ERROR:
case ErrorCodes.JOB_ERROR:
case ErrorCodes.THUMBNAIL_GENERATION_ERROR:
case ErrorCodes.PHOTO_GENERATION_ERROR:
case ErrorCodes.SERVER_ERROR:
return Logger.error
default:
return Logger.warn
}
}
}

View File

@ -132,8 +132,7 @@ export class RenderingMWs {
): void {
if (err instanceof ErrorDTO) {
if (err.details) {
Logger.warn('Handled error:');
LoggerRouter.log(Logger.warn, req, res);
LoggerRouter.log(logFn, req, res);
// use separate rendering for detailsStr
const d = err.detailsStr;
delete err.detailsStr;