@@ -4,7 +4,7 @@ import { onError } from "@apollo/client/link/error";
4
4
import { RetryLink } from "@apollo/client/link/retry" ;
5
5
import { setContext } from "@apollo/client/link/context" ;
6
6
import AgentKeepAlive from "agentkeepalive" ;
7
- import consola from "consola " ;
7
+ import { getLogger , type AlokaiContainer } from "@vue-storefront/middleware " ;
8
8
import { handleRetry } from "./linkHandlers" ;
9
9
import { Config } from "../../types/setup" ;
10
10
import possibleTypes from "../../types/possibleTypes.json" ;
@@ -15,8 +15,10 @@ const agent = new HttpsAgent({
15
15
timeout : 30000 ,
16
16
} ) ;
17
17
18
- const createErrorHandler = ( ) =>
18
+ const createErrorHandler = ( alokai : AlokaiContainer ) =>
19
19
onError ( ( { graphQLErrors, networkError } ) => {
20
+ const logger = getLogger ( alokai ) ;
21
+
20
22
if ( graphQLErrors ) {
21
23
graphQLErrors . forEach ( ( { message, locations, path, extensions } ) => {
22
24
// Mute all GraphQL authorization errors
@@ -26,27 +28,28 @@ const createErrorHandler = () =>
26
28
27
29
if ( ! message . includes ( "Resource Owner Password Credentials Grant" ) ) {
28
30
if ( ! locations ) {
29
- consola . error ( `[GraphQL error]: Message: ${ message } , Path: ${ path } ` ) ;
31
+ logger . error ( message , { path } ) ;
30
32
return ;
31
33
}
32
34
33
35
const parsedLocations = locations . map ( ( { column, line } ) => `[column: ${ column } , line: ${ line } ]` ) ;
34
36
35
- consola . error ( `[GraphQL error]: Message: ${ message } , Location: ${ parsedLocations . join ( ", " ) } , Path: ${ path } ` ) ;
37
+ logger . error ( message , { path , location : parsedLocations . join ( ", " ) } ) ;
36
38
}
37
39
} ) ;
38
40
}
39
41
40
42
if ( networkError ) {
41
- consola . error ( `[Network error]: ${ networkError } ` ) ;
43
+ logger . error ( networkError , { type : "Network Error" } ) ;
42
44
}
43
45
} ) ;
44
46
45
47
export const apolloLinkFactory = (
46
48
settings : Config ,
47
- handlers ? : {
49
+ handlers : {
48
50
apolloLink ?: ApolloLink ;
49
- }
51
+ } ,
52
+ alokai : AlokaiContainer
50
53
) => {
51
54
const baseLink =
52
55
handlers ?. apolloLink ||
@@ -66,10 +69,10 @@ export const apolloLinkFactory = (
66
69
...settings . customApolloHttpLinkOptions ,
67
70
} ) ;
68
71
69
- const onErrorLink = createErrorHandler ( ) ;
72
+ const onErrorLink = createErrorHandler ( alokai ) ;
70
73
71
74
const errorRetry = new RetryLink ( {
72
- attempts : handleRetry ( ) ,
75
+ attempts : handleRetry ( { alokai } ) ,
73
76
delay : ( ) => 0 ,
74
77
} ) ;
75
78
0 commit comments