-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ata-deletion
- Loading branch information
Showing
170 changed files
with
3,244 additions
and
5,986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
apps/server/src/core/error/loggable/axios-error.loggable.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
apps/server/src/core/error/loggable/axios-error.loggable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './error.loggable'; | ||
export * from './axios-error.loggable'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.