chore: application start error message (#4477)

This commit is contained in:
ChengLei Shao 2024-05-24 08:26:08 +08:00 committed by GitHub
parent cece85b335
commit bbbb409565
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -801,7 +801,7 @@ export class Database extends EventEmitter implements AsyncEmitter {
/* istanbul ignore next -- @preserve */
async auth(options: Omit<QueryOptions, 'retry'> & { retry?: number | Pick<QueryOptions, 'retry'> } = {}) {
const { retry = 10, ...others } = options;
const { retry = 5, ...others } = options;
const startingDelay = 50;
const timeMultiple = 2;
@ -831,7 +831,7 @@ export class Database extends EventEmitter implements AsyncEmitter {
timeMultiple: timeMultiple,
});
} catch (error) {
throw new Error('Connection failed, please check your database connection credentials and try again.');
throw new Error(`Unable to connect to the database`, { cause: error });
}
}

View File

@ -34,8 +34,20 @@ export const errors: AppErrors = {
APP_ERROR: {
status: 503,
message: ({ app }) => {
return AppSupervisor.getInstance().appErrors[app.name]?.message;
const error = AppSupervisor.getInstance().appErrors[app.name];
if (!error) {
return '';
}
let message = error.message;
if ((error as any).cause) {
message = `${message}: ${(error as any).cause.message}`;
}
return message;
},
code: ({ app }): string => {
const error = AppSupervisor.getInstance().appErrors[app.name];
return error['code'] || 'APP_ERROR';