-
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.
N21-1456 improves logging for oauth calls
- Loading branch information
Showing
10 changed files
with
462 additions
and
121 deletions.
There are no files selected for viewing
390 changes: 284 additions & 106 deletions
390
apps/server/src/infra/oauth-provider/hydra/hydra.adapter.spec.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
apps/server/src/infra/oauth-provider/loggable/hydra-oauth-loggable-exception.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,38 @@ | ||
import { HydraOauthLoggableException } from './hydra-oauth-loggable-exception'; | ||
|
||
describe(HydraOauthLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const url = 'url'; | ||
const method = 'method'; | ||
const errorMessage = 'thisIsTheMessage'; | ||
const errorStatusCode = 127; | ||
|
||
const exception = new HydraOauthLoggableException(url, method, errorMessage, errorStatusCode); | ||
|
||
return { | ||
exception, | ||
url, | ||
method, | ||
errorMessage, | ||
errorStatusCode, | ||
}; | ||
}; | ||
|
||
it('should return the correct log message', () => { | ||
const { exception, url, method, errorMessage } = setup(); | ||
|
||
const message = exception.getLogMessage(); | ||
|
||
expect(message).toEqual({ | ||
type: 'HYDRA_OAUTH_ERROR', | ||
message: 'Hydra oauth error occurred', | ||
stack: expect.stringContaining(`HydraOauthLoggableException: ${errorMessage}`) as string, | ||
data: { | ||
url, | ||
method, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
apps/server/src/infra/oauth-provider/loggable/hydra-oauth-loggable-exception.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,25 @@ | ||
import { HttpException } from '@nestjs/common/exceptions/http.exception'; | ||
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
|
||
export class HydraOauthLoggableException extends HttpException implements Loggable { | ||
constructor( | ||
private readonly url: string, | ||
private readonly method: string, | ||
private readonly errorMessage: string, | ||
private readonly errorStatusCode: number | ||
) { | ||
super(errorMessage, errorStatusCode); | ||
} | ||
|
||
getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'HYDRA_OAUTH_ERROR', | ||
message: 'Hydra oauth error occurred', | ||
stack: this.stack, | ||
data: { | ||
url: this.url, | ||
method: this.method, | ||
}, | ||
}; | ||
} | ||
} |
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 @@ | ||
export * from './hydra-oauth-loggable-exception'; |
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
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
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,21 @@ | ||
import { isAxiosError } from './axios.util'; | ||
|
||
describe('axios.util', () => { | ||
describe('isAxiosError', () => { | ||
it('should return true when error is an axios error', () => { | ||
const axiosError = { | ||
isAxiosError: true, | ||
}; | ||
expect(isAxiosError(axiosError)).toBe(true); | ||
}); | ||
|
||
it('should return false when error is not an axios error', () => { | ||
const error = new Error('some error'); | ||
expect(isAxiosError(error)).toBe(false); | ||
}); | ||
|
||
it('should return false when error is undefined', () => { | ||
expect(isAxiosError(undefined)).toBe(false); | ||
}); | ||
}); | ||
}); |
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,5 @@ | ||
import { AxiosError } from 'axios'; | ||
|
||
export function isAxiosError(error: unknown): error is AxiosError { | ||
return !!(error && typeof error === 'object' && 'isAxiosError' in error); | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './converter.util'; | ||
export * from './guard-against'; | ||
export * from './axios.util'; |