Skip to content

Commit 034cab8

Browse files
authored
N21-1456 improves oauth error handling (#4539)
1 parent 249454c commit 034cab8

16 files changed

+549
-125
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { axiosErrorFactory } from '@shared/testing/factory';
2+
import { AxiosError } from 'axios';
3+
import { AxiosErrorLoggable } from './axios-error.loggable';
4+
5+
describe(AxiosErrorLoggable.name, () => {
6+
describe('getLogMessage', () => {
7+
const setup = () => {
8+
const error = {
9+
error: 'invalid_request',
10+
};
11+
const type = 'mockType';
12+
const axiosError: AxiosError = axiosErrorFactory.withError(error).build();
13+
14+
const axiosErrorLoggable = new AxiosErrorLoggable(axiosError, type);
15+
16+
return { axiosErrorLoggable, error, axiosError };
17+
};
18+
19+
it('should return error log message', () => {
20+
const { axiosErrorLoggable, error, axiosError } = setup();
21+
22+
const result = axiosErrorLoggable.getLogMessage();
23+
24+
expect(result).toEqual({
25+
type: 'mockType',
26+
message: axiosError.message,
27+
data: JSON.stringify(error),
28+
stack: 'mockStack',
29+
});
30+
});
31+
});
32+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { HttpException, HttpStatus } from '@nestjs/common';
2+
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
3+
import { AxiosError } from 'axios';
4+
5+
export class AxiosErrorLoggable extends HttpException implements Loggable {
6+
constructor(private readonly axiosError: AxiosError, protected readonly type: string) {
7+
super(JSON.stringify(axiosError.response?.data), axiosError.status ?? HttpStatus.INTERNAL_SERVER_ERROR, {
8+
cause: axiosError.cause,
9+
});
10+
}
11+
12+
getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
13+
return {
14+
message: this.axiosError.message,
15+
type: this.type,
16+
data: JSON.stringify(this.axiosError.response?.data),
17+
stack: this.axiosError.stack,
18+
};
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './error.loggable';
2+
export * from './axios-error.loggable';

0 commit comments

Comments
 (0)