Skip to content

Commit 99b4136

Browse files
pkiparraMalteSehmer
andcommitted
🚧 wip
Co-Authored-By: Malte Sehmer <[email protected]>
1 parent 81fb287 commit 99b4136

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/util/error.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AxiosError } from "axios";
1+
import axios, { AxiosError } from "axios";
22
import {
33
DELEGATE_TO_FRONTEND_CODE,
44
IntegrationErrorType,
@@ -7,7 +7,7 @@ import {
77
import { errorLogger } from "./logger.util";
88

99
export const throwAndDelegateError = (
10-
error: Error | AxiosError,
10+
error: AxiosError | Error,
1111
source: string,
1212
apiKey: string | undefined,
1313
logMessage?: string
@@ -24,8 +24,7 @@ export const throwAndDelegateError = (
2424
} else {
2525
errorLogger(source, errorMessage, apiKey);
2626
}
27-
28-
if (error instanceof AxiosError) {
27+
if (axios.isAxiosError(error)) {
2928
const status = error.response?.status || 500;
3029
var errorType: IntegrationErrorType;
3130
switch (status) {
@@ -44,9 +43,12 @@ export const throwAndDelegateError = (
4443
errorType = IntegrationErrorType.INTEGRATION_ERROR_UNAVAILABLE;
4544
break;
4645
default:
46+
console.log("bin default weil status= ", status);
4747
throw new ServerError(status, `${source} (${errorMessage})`);
4848
}
49+
console.log("bin außerhalb vom switch weil status= ", status);
4950
throw new ServerError(DELEGATE_TO_FRONTEND_CODE, errorType);
5051
}
52+
console.log("kein axios");
5153
throw new ServerError(500, "An internal error occurred");
5254
};

src/util/logger.util.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const infoLogger = (
1313
apiKey: string | undefined,
1414
...args: unknown[]
1515
): void => {
16-
logger(console.info, source, message, apiKey, args);
16+
logger(console.info, source, message, apiKey, ...args);
1717
};
1818

1919
/**
@@ -29,7 +29,7 @@ export const errorLogger = (
2929
apiKey: string | undefined,
3030
...args: unknown[]
3131
): void => {
32-
logger(console.error, source, message, apiKey, args);
32+
logger(console.error, source, message, apiKey, ...args);
3333
};
3434

3535
/**
@@ -45,7 +45,7 @@ export const warnLogger = (
4545
apiKey?: string,
4646
...args: unknown[]
4747
): void => {
48-
logger(console.warn, source, message, apiKey, args);
48+
logger(console.warn, source, message, apiKey, ...args);
4949
};
5050

5151
const logger = (
@@ -56,23 +56,22 @@ const logger = (
5656
...args: unknown[]
5757
): void => {
5858
// eslint-disable-next-line no-console
59-
if (apiKey) {
60-
logFn(
61-
constructLogMessage(
62-
`[${anonymizeKey(apiKey)}]`,
63-
`[${source}]`,
64-
message,
65-
...args
66-
)
67-
);
68-
} else {
69-
logFn(constructLogMessage(`[${source}]`, message, ...args));
70-
}
59+
const anonymizedApiKey = apiKey ? anonymizeKey(apiKey) : undefined;
60+
61+
logFn(
62+
constructLogMessage(
63+
anonymizedApiKey ? `[${anonymizedApiKey}]` : undefined,
64+
`[${source}]`,
65+
message
66+
),
67+
...args
68+
);
7169
};
7270

7371
const constructLogMessage = (...args: unknown[]): string =>
7472
`${args
7573
.flat()
74+
.filter((item) => item != undefined)
7675
.map((item: unknown) => {
7776
if (Array.isArray(item) && item.length == 0) return;
7877
return typeof item !== "string" ? JSON.stringify(item) : item;

0 commit comments

Comments
 (0)