From 41c0d6fc81e70d77fc7ee80004cbfe07586aa143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Mon, 12 Aug 2024 13:39:22 +0200 Subject: [PATCH] exclude webpack config from coverage --- sonar-project.properties | 2 +- src/utils/api/api.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sonar-project.properties b/sonar-project.properties index 9161d99..634b7ec 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -8,7 +8,7 @@ sonar.tests=. sonar.exclusions=src/serverApi/**/*,**/locales/**.ts # Exclude scripts from root folder, app setup scripts from src and route config from coverage -sonar.coverage.exclusions=/*,src/*,src/router/*,webpack-config/**/* +sonar.coverage.exclusions=/*,src/*,src/router/*,config/**/* # Include test files and test utils in test scope sonar.test.inclusions=tests/**/*,**/*.unit.ts,**/*.unit.js diff --git a/src/utils/api/api.ts b/src/utils/api/api.ts index 84beccd..3c0abd4 100644 --- a/src/utils/api/api.ts +++ b/src/utils/api/api.ts @@ -31,19 +31,23 @@ export const mapAxiosErrorToResponseError = ( Record >(error) ) { + if (!error.response) { + return apiError; + } + const errorPayload: | ApiValidationError | ApiResponseError | string - | undefined = error.response?.data; + | undefined = error.response.data; if (errorPayload && isObject(errorPayload)) { apiError = errorPayload; } else if (typeof errorPayload === "string") { apiError.message = errorPayload; - apiError.code = error.response?.status ?? apiError.code; + apiError.code = error.response.status ?? apiError.code; apiError.type = error.code ?? apiError.type; - apiError.title = error.response?.statusText ?? apiError.title; + apiError.title = error.response.statusText ?? apiError.title; } } return apiError;