File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -4,15 +4,21 @@ import {
4
4
IntegrationErrorType ,
5
5
ServerError ,
6
6
} from "../models" ;
7
+ import { errorLogger } from "./logger.util" ;
7
8
8
- export const generateError = (
9
+ export const throwAndDelegateError = (
9
10
error : Error | AxiosError ,
10
- intentMessage : string
11
+ source : string ,
12
+ apiKey ?: string
11
13
) => {
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
15
19
: error . message ;
20
+ errorLogger ( source , message , apiKey ) ;
21
+ if ( error instanceof AxiosError ) {
16
22
const status = error . response ?. status || 500 ;
17
23
var errorType : IntegrationErrorType ;
18
24
switch ( status ) {
@@ -31,7 +37,7 @@ export const generateError = (
31
37
errorType = IntegrationErrorType . INTEGRATION_ERROR_UNAVAILABLE ;
32
38
break ;
33
39
default :
34
- throw new ServerError ( status , `${ intentMessage } (${ message } )` ) ;
40
+ throw new ServerError ( status , `${ source } (${ message } )` ) ;
35
41
}
36
42
throw new ServerError ( DELEGATE_TO_FRONTEND_CODE , errorType ) ;
37
43
}
You can’t perform that action at this time.
0 commit comments