mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
fix(server): auto-reconnect to database (#12320)
This commit is contained in:
parent
1783dfd393
commit
12b65e3c24
10 changed files with 130 additions and 46 deletions
|
|
@ -1,3 +1,7 @@
|
|||
import { HttpException } from '@nestjs/common';
|
||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||
import { TypeORMError } from 'typeorm';
|
||||
|
||||
type ColorTextFn = (text: string) => string;
|
||||
|
||||
const isColorAllowed = () => !process.env.NO_COLOR;
|
||||
|
|
@ -15,3 +19,22 @@ export const LogColor = {
|
|||
export const LogStyle = {
|
||||
bold: colorIfAllowed((text: string) => `\u001B[1m${text}\u001B[0m`),
|
||||
};
|
||||
|
||||
export const logGlobalError = (logger: ILoggerRepository, error: Error) => {
|
||||
if (error instanceof HttpException) {
|
||||
const status = error.getStatus();
|
||||
const response = error.getResponse();
|
||||
logger.debug(`HttpException(${status}): ${JSON.stringify(response)}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error instanceof TypeORMError) {
|
||||
logger.error(`Database error: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
logger.error(`Unknown error: ${error}`);
|
||||
return;
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue