Skip to content

Commit c88d5dc

Browse files
committed
🎨 Refactor and rename error.ts
1 parent 431d126 commit c88d5dc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/util/error.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import {
44
IntegrationErrorType,
55
ServerError,
66
} from "../models";
7+
import { errorLogger } from "./logger.util";
78

8-
export const generateError = (
9+
export const throwAndDelegateError = (
910
error: Error | AxiosError,
10-
intentMessage: string
11+
source: string,
12+
apiKey?: string
1113
) => {
12-
if (error instanceof AxiosError) {
13-
const message = error.response?.data
14-
? JSON.stringify(error.response?.data)
14+
const message =
15+
error instanceof AxiosError
16+
? error.response?.data
17+
? JSON.stringify(error.response?.data)
18+
: error.message
1519
: error.message;
20+
errorLogger(source, message, apiKey);
21+
if (error instanceof AxiosError) {
1622
const status = error.response?.status || 500;
1723
var errorType: IntegrationErrorType;
1824
switch (status) {
@@ -31,7 +37,7 @@ export const generateError = (
3137
errorType = IntegrationErrorType.INTEGRATION_ERROR_UNAVAILABLE;
3238
break;
3339
default:
34-
throw new ServerError(status, `${intentMessage} (${message})`);
40+
throw new ServerError(status, `${source} (${message})`);
3541
}
3642
throw new ServerError(DELEGATE_TO_FRONTEND_CODE, errorType);
3743
}

0 commit comments

Comments
 (0)