Skip to content

Commit

Permalink
Merge branch 'BC-5629-batch-deletion-mechanism' into BC-5628-cyclic-d…
Browse files Browse the repository at this point in the history
…ata-deletion
  • Loading branch information
bn-pass committed Nov 15, 2023
2 parents 199f582 + d61d6c8 commit 1c5051d
Show file tree
Hide file tree
Showing 170 changed files with 3,244 additions and 5,986 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/* istanbul ignore file */
import { BootstrapConsole } from 'nestjs-console';
import { DeletionConsoleModule } from './deletion-console.module';
import { DeletionConsoleModule } from '@modules/deletion';

const bootstrap = new BootstrapConsole({
module: DeletionConsoleModule,
useDecorators: true,
});

const logErrorAndSetExitCode = (err: unknown) => {
// eslint-disable-next-line no-console
console.error(err);
process.exitCode = 1;
};

bootstrap
.init()
.then(async (app) => {
Expand All @@ -18,13 +24,7 @@ bootstrap
} catch (err) {
await app.close();

// eslint-disable-next-line no-console
console.error(err);
process.exitCode = 1;
logErrorAndSetExitCode(err);
}
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
process.exitCode = 1;
});
.catch((err) => logErrorAndSetExitCode(err));
32 changes: 32 additions & 0 deletions apps/server/src/core/error/loggable/axios-error.loggable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { axiosErrorFactory } from '@shared/testing/factory';
import { AxiosError } from 'axios';
import { AxiosErrorLoggable } from './axios-error.loggable';

describe(AxiosErrorLoggable.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const error = {
error: 'invalid_request',
};
const type = 'mockType';
const axiosError: AxiosError = axiosErrorFactory.withError(error).build();

const axiosErrorLoggable = new AxiosErrorLoggable(axiosError, type);

return { axiosErrorLoggable, error, axiosError };
};

it('should return error log message', () => {
const { axiosErrorLoggable, error, axiosError } = setup();

const result = axiosErrorLoggable.getLogMessage();

expect(result).toEqual({
type: 'mockType',
message: axiosError.message,
data: JSON.stringify(error),
stack: 'mockStack',
});
});
});
});
20 changes: 20 additions & 0 deletions apps/server/src/core/error/loggable/axios-error.loggable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HttpException, HttpStatus } from '@nestjs/common';
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { AxiosError } from 'axios';

export class AxiosErrorLoggable extends HttpException implements Loggable {
constructor(private readonly axiosError: AxiosError, protected readonly type: string) {
super(JSON.stringify(axiosError.response?.data), axiosError.status ?? HttpStatus.INTERNAL_SERVER_ERROR, {
cause: axiosError.cause,
});
}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
message: this.axiosError.message,
type: this.type,
data: JSON.stringify(this.axiosError.response?.data),
stack: this.axiosError.stack,
};
}
}
2 changes: 2 additions & 0 deletions apps/server/src/core/error/loggable/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './error.loggable';
export * from './axios-error.loggable';
2 changes: 1 addition & 1 deletion apps/server/src/core/logger/types/logging.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ErrorLogMessage = {
error?: Error;
type: string; // TODO: use enum
stack?: string;
data?: { [key: string]: string | number | undefined };
data?: { [key: string]: string | number | boolean | undefined };
};

export type ValidationErrorLogMessage = {
Expand Down
Loading

0 comments on commit 1c5051d

Please sign in to comment.