@@ -4,7 +4,7 @@ import { onError } from "@apollo/client/link/error";
44import { RetryLink } from "@apollo/client/link/retry" ;
55import { setContext } from "@apollo/client/link/context" ;
66import AgentKeepAlive from "agentkeepalive" ;
7- import consola from "consola " ;
7+ import { getLogger , type AlokaiContainer } from "@vue-storefront/middleware " ;
88import { handleRetry } from "./linkHandlers" ;
99import { Config } from "../../types/setup" ;
1010import possibleTypes from "../../types/possibleTypes.json" ;
@@ -15,8 +15,10 @@ const agent = new HttpsAgent({
1515 timeout : 30000 ,
1616} ) ;
1717
18- const createErrorHandler = ( ) =>
18+ const createErrorHandler = ( alokai : AlokaiContainer ) =>
1919 onError ( ( { graphQLErrors, networkError } ) => {
20+ const logger = getLogger ( alokai ) ;
21+
2022 if ( graphQLErrors ) {
2123 graphQLErrors . forEach ( ( { message, locations, path, extensions } ) => {
2224 // Mute all GraphQL authorization errors
@@ -26,27 +28,28 @@ const createErrorHandler = () =>
2628
2729 if ( ! message . includes ( "Resource Owner Password Credentials Grant" ) ) {
2830 if ( ! locations ) {
29- consola . error ( `[GraphQL error]: Message: ${ message } , Path: ${ path } ` ) ;
31+ logger . error ( message , { path } ) ;
3032 return ;
3133 }
3234
3335 const parsedLocations = locations . map ( ( { column, line } ) => `[column: ${ column } , line: ${ line } ]` ) ;
3436
35- consola . error ( `[GraphQL error]: Message: ${ message } , Location: ${ parsedLocations . join ( ", " ) } , Path: ${ path } ` ) ;
37+ logger . error ( message , { path , location : parsedLocations . join ( ", " ) } ) ;
3638 }
3739 } ) ;
3840 }
3941
4042 if ( networkError ) {
41- consola . error ( `[Network error]: ${ networkError } ` ) ;
43+ logger . error ( networkError , { type : "Network Error" } ) ;
4244 }
4345 } ) ;
4446
4547export const apolloLinkFactory = (
4648 settings : Config ,
47- handlers ? : {
49+ handlers : {
4850 apolloLink ?: ApolloLink ;
49- }
51+ } ,
52+ alokai : AlokaiContainer
5053) => {
5154 const baseLink =
5255 handlers ?. apolloLink ||
@@ -66,10 +69,10 @@ export const apolloLinkFactory = (
6669 ...settings . customApolloHttpLinkOptions ,
6770 } ) ;
6871
69- const onErrorLink = createErrorHandler ( ) ;
72+ const onErrorLink = createErrorHandler ( alokai ) ;
7073
7174 const errorRetry = new RetryLink ( {
72- attempts : handleRetry ( ) ,
75+ attempts : handleRetry ( { alokai } ) ,
7376 delay : ( ) => 0 ,
7477 } ) ;
7578
0 commit comments