From 39164c64a89a894ab636f740779179a3139e4e72 Mon Sep 17 00:00:00 2001 From: Arne Gnisa Date: Thu, 9 Nov 2023 17:23:18 +0100 Subject: [PATCH] N21-1456 changes errors 2 --- .../loggable/axios-error.loggable.spec.ts | 33 +++++-------------- .../error/loggable/axios-error.loggable.ts | 4 +-- ...ra-oauth-failed-loggable-exception.spec.ts | 2 +- .../token-request-loggable-exception.spec.ts | 2 +- .../testing/factory/axios-error.factory.ts | 12 +------ 5 files changed, 14 insertions(+), 39 deletions(-) diff --git a/apps/server/src/core/error/loggable/axios-error.loggable.spec.ts b/apps/server/src/core/error/loggable/axios-error.loggable.spec.ts index 835b77f5c9c..a20fe37a8fe 100644 --- a/apps/server/src/core/error/loggable/axios-error.loggable.spec.ts +++ b/apps/server/src/core/error/loggable/axios-error.loggable.spec.ts @@ -1,43 +1,28 @@ +import { axiosErrorFactory } from '@shared/testing/factory/axios-error.factory'; import { AxiosError } from 'axios'; import { AxiosErrorLoggable } from './axios-error.loggable'; describe(AxiosErrorLoggable.name, () => { describe('getLogMessage', () => { const setup = () => { - const axiosError = { - response: { - data: { - error: { - message: 'mockMessage', - }, - }, - }, - status: 400, - stack: 'mockStack', - } as unknown as AxiosError; + const error = new Error('some error message'); const type = 'mockType'; + const axiosError: AxiosError = axiosErrorFactory.withError(error).build(); + const axiosErrorLoggable = new AxiosErrorLoggable(axiosError, type); - return { axiosErrorLoggable }; + + return { axiosErrorLoggable, error, axiosError }; }; it('should return error log message', () => { - const { axiosErrorLoggable } = setup(); + const { axiosErrorLoggable, error, axiosError } = setup(); const result = axiosErrorLoggable.getLogMessage(); expect(result).toEqual({ type: 'mockType', - error: { - response: { - data: { - error: { - message: 'mockMessage', - }, - }, - }, - status: 400, - stack: 'mockStack', - }, + message: axiosError.message, + data: error, stack: 'mockStack', }); }); diff --git a/apps/server/src/core/error/loggable/axios-error.loggable.ts b/apps/server/src/core/error/loggable/axios-error.loggable.ts index 3dfd9fab248..389914883d4 100644 --- a/apps/server/src/core/error/loggable/axios-error.loggable.ts +++ b/apps/server/src/core/error/loggable/axios-error.loggable.ts @@ -4,14 +4,14 @@ 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 ?? 500, { cause: axiosError.cause }); + super(axiosError.response?.data as string, axiosError.status ?? 500, { cause: axiosError.cause }); } getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { return { message: this.axiosError.message, type: this.type, - error: this.axiosError.response?.data as Error, + data: this.axiosError.response?.data as string, stack: this.axiosError.stack, }; } diff --git a/apps/server/src/infra/oauth-provider/loggable/hydra-oauth-failed-loggable-exception.spec.ts b/apps/server/src/infra/oauth-provider/loggable/hydra-oauth-failed-loggable-exception.spec.ts index 71e698f5b07..76e1f2771bd 100644 --- a/apps/server/src/infra/oauth-provider/loggable/hydra-oauth-failed-loggable-exception.spec.ts +++ b/apps/server/src/infra/oauth-provider/loggable/hydra-oauth-failed-loggable-exception.spec.ts @@ -26,7 +26,7 @@ describe(HydraOauthFailedLoggableException.name, () => { type: 'HYDRA_OAUTH_FAILED', message: axiosError.message, stack: axiosError.stack, - error, + data: error, }); }); }); diff --git a/apps/server/src/modules/oauth/loggable/token-request-loggable-exception.spec.ts b/apps/server/src/modules/oauth/loggable/token-request-loggable-exception.spec.ts index 8650957369d..2af39ffa4c9 100644 --- a/apps/server/src/modules/oauth/loggable/token-request-loggable-exception.spec.ts +++ b/apps/server/src/modules/oauth/loggable/token-request-loggable-exception.spec.ts @@ -24,7 +24,7 @@ describe(TokenRequestLoggableException.name, () => { expect(logMessage).toStrictEqual({ type: 'OAUTH_TOKEN_REQUEST_ERROR', message: axiosError.message, - error, + data: error, stack: axiosError.stack, }); }); diff --git a/apps/server/src/shared/testing/factory/axios-error.factory.ts b/apps/server/src/shared/testing/factory/axios-error.factory.ts index 372a9bc9b26..b1cf2462add 100644 --- a/apps/server/src/shared/testing/factory/axios-error.factory.ts +++ b/apps/server/src/shared/testing/factory/axios-error.factory.ts @@ -6,7 +6,6 @@ import { axiosResponseFactory } from './axios-response.factory'; import { BaseFactory } from './base.factory'; type AxiosErrorProps = { - data: T; status: number; statusText: string; headers: AxiosHeaders; @@ -20,8 +19,6 @@ type AxiosErrorProps = { }; class AxiosErrorImp implements AxiosError { - data: T; - status: number; statusText: string; @@ -43,7 +40,6 @@ class AxiosErrorImp implements AxiosError { stack: string; constructor(props: AxiosErrorProps) { - this.data = props.data; this.status = props.status; this.statusText = props.statusText; this.headers = new AxiosHeaders(props.headers); @@ -73,12 +69,6 @@ export class AxiosErrorFactory extends BaseFactory, Axios export const axiosErrorFactory = AxiosErrorFactory.define(AxiosErrorImp, () => { return { - data: { - error: { - message: 'Some error message', - code: '123', - }, - }, status: HttpStatus.BAD_REQUEST, statusText: 'Bad Request', headers: new AxiosHeaders(), @@ -88,6 +78,6 @@ export const axiosErrorFactory = AxiosErrorFactory.define(AxiosErrorImp, () => { message: 'Bad Request', name: 'BadRequest', response: axiosResponseFactory.build({ status: HttpStatus.BAD_REQUEST }), - stack: '', + stack: 'mockStack', }; });