You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/core/stack.js
+23-13Lines changed: 23 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,7 @@ let errorRetry = [408, 429]
25
25
* @param param.fetchOptions.retryCondition - A function to determine if the error can be retried. Default retry is on status codes 408, 429.
26
26
* @param param.fetchOptions.retryDelayOptions.base - The base number of milliseconds to use in the exponential backoff for operation retries.
27
27
* @param param.fetchOptions.retryDelayOptions.customBackoff - A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds.
28
+
* @param param.fetchOptions.logHandler - A function for logging of requests, responses and errors
28
29
*
29
30
* @example
30
31
* var Stack = Contentstack.Stack({
@@ -33,7 +34,7 @@ let errorRetry = [408, 429]
33
34
* 'environment':'environment_name',
34
35
* 'region': 'us',
35
36
* 'fetchOptions': {
36
-
*
37
+
*
37
38
* }
38
39
* });
39
40
*
@@ -49,6 +50,18 @@ export default class Stack {
49
50
returntrue;
50
51
}
51
52
returnfalse
53
+
},
54
+
logHandler: (level,data)=>{
55
+
if(level==='error'&&data){
56
+
console.error(`[error] ${data}`)
57
+
return
58
+
}elseif(level==='warning'&&data){
59
+
console.warn(`[warning] ${data}`)
60
+
return
61
+
}elseif(level==='info'&&data){
62
+
console.info(`[info] ${data}`)
63
+
return
64
+
}
52
65
}
53
66
};
54
67
this.config=Utils.mergeDeep({},config)
@@ -80,11 +93,10 @@ export default class Stack {
80
93
this.environment=stack_arguments[0].environment;
81
94
returnthis;
82
95
}else{
83
-
console.error("Kindly provide valid object parameters. The specified API Key, Delivery Token, or Environment Name is invalid.");
84
-
break;
96
+
this.fetchOptions.logHandler('error',"Kindly provide valid object parameters. The specified API Key, Delivery Token, or Environment Name is invalid.");
85
97
}
86
98
case3:
87
-
console.warn("WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!");
99
+
this.fetchOptions.logHandler('warning',"WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!");
console.error("Kindly provide valid string parameters.");
97
-
break;
108
+
this.fetchOptions.logHandler('error',"Kindly provide valid string parameters.");
98
109
}
99
110
case4:
100
-
console.warn("WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!");
111
+
this.fetchOptions.logHandler('warning',"WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!");
@@ -116,15 +127,15 @@ export default class Stack {
116
127
}
117
128
returnthis;
118
129
case5:
119
-
console.warn("WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!");
130
+
this.fetchOptions.logHandler('warning',"WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!");
0 commit comments