@ampsec/platform-client 70.5.0 → 70.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,6 +15,7 @@ export type AmpRestClientOptions = {
|
|
|
15
15
|
client?: AxiosStatic;
|
|
16
16
|
/** Throws errors on non-200 responses if `true`*/
|
|
17
17
|
strict?: boolean;
|
|
18
|
+
onError?: (error: unknown) => void;
|
|
18
19
|
};
|
|
19
20
|
export type RestClientOptions = {
|
|
20
21
|
baseUrl?: string;
|
|
@@ -26,6 +27,7 @@ export type RestClientOptions = {
|
|
|
26
27
|
client?: AxiosStatic;
|
|
27
28
|
/** Throws errors on non-200 responses if `true`. Default `false` */
|
|
28
29
|
strict?: boolean;
|
|
30
|
+
onError?: (error: unknown) => void;
|
|
29
31
|
};
|
|
30
32
|
/**
|
|
31
33
|
* RestClient is a generic interface for making REST calls.
|
|
@@ -104,6 +104,9 @@ class DefaultRestClient {
|
|
|
104
104
|
this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
|
|
105
105
|
this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
106
106
|
this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
|
|
107
|
+
if (options.onError) {
|
|
108
|
+
this.ampAxios.interceptors.response.use(response => response, options.onError);
|
|
109
|
+
}
|
|
107
110
|
this.retryStrategy = (_d = options.retryStrategy) !== null && _d !== void 0 ? _d : retry_rest_1.noopRestRetryStrategy;
|
|
108
111
|
this.rateLimitStrategy = (_e = options.rateLimitStrategy) !== null && _e !== void 0 ? _e : rateLimit_rest_1.noopRestClientRateLimitStrategy;
|
|
109
112
|
this.baseUrl = options.baseUrl;
|
|
@@ -121,6 +124,7 @@ const getAmpRestClient = (options) => {
|
|
|
121
124
|
logger: options.logger,
|
|
122
125
|
client: options.client,
|
|
123
126
|
strict: lodash_1.default.isUndefined(options.strict) ? true : options.strict,
|
|
127
|
+
onError: options.onError,
|
|
124
128
|
});
|
|
125
129
|
return ampClient;
|
|
126
130
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RestClient.js","sourceRoot":"","sources":["../../../../src/services/rest/RestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,4CAAoB;AACpB,+CAA4D;AAG5D,6CAA4E;AAC5E,mCAAmD;AACnD,qDAAiI;AACjI,2CAAoD;
|
|
1
|
+
{"version":3,"file":"RestClient.js","sourceRoot":"","sources":["../../../../src/services/rest/RestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,4CAAoB;AACpB,+CAA4D;AAG5D,6CAA4E;AAC5E,mCAAmD;AACnD,qDAAiI;AACjI,2CAAoD;AAqCpD;;;;;;GAMG;AACH,MAAa,iBAAiB;IAQ5B,YAAY,UAA6B,EAAE;;QA+B3C,SAAI,GAAG,KAAK,EAAE,OAAoB,EAAyB,EAAE;;YAC3D,MAAM,GAAG,GAAG,gBAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAC,GAAG,EAAC,CAAC,CAAC,CAAC,yBAAyB;gBACnD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBAC7C,IAAI,IAAI,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;oBACrC,MAAM,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,UAAU,iBAAiB,CAAC,CAAC;gBACtE,CAAC;gBACD,OAAO;oBACL,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,OAAO,EAAE,IAAA,sBAAc,E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AC,iBAAiB,mCAAI,gDAA+B,CAAC;QACtF,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,KAAK,CAAC;IACxC,CAAC;CAoCF;AA1ED,8CA0EC;AAEM,MAAM,gBAAgB,GAAG,CAAC,OAA6B,EAAc,EAAE;IAC5E,MAAM,SAAS,GAAG,IAAI,iBAAiB,CAAC;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE;SACzC;QACD,iBAAiB,EAAE,IAAI,kDAAiC,CAAC,EAAE,CAAC;QAC5D,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,gBAAC,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM;QAC7D,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B"}
|
package/package.json
CHANGED
|
@@ -18,6 +18,7 @@ export type AmpRestClientOptions = {
|
|
|
18
18
|
client?: AxiosStatic;
|
|
19
19
|
/** Throws errors on non-200 responses if `true`*/
|
|
20
20
|
strict?: boolean;
|
|
21
|
+
onError?: (error: unknown) => void;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
export type RestClientOptions = {
|
|
@@ -30,6 +31,7 @@ export type RestClientOptions = {
|
|
|
30
31
|
client?: AxiosStatic;
|
|
31
32
|
/** Throws errors on non-200 responses if `true`. Default `false` */
|
|
32
33
|
strict?: boolean;
|
|
34
|
+
onError?: (error: unknown) => void;
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
/**
|
|
@@ -79,6 +81,9 @@ export class DefaultRestClient implements RestClient {
|
|
|
79
81
|
this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
|
|
80
82
|
this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
81
83
|
this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
|
|
84
|
+
if (options.onError) {
|
|
85
|
+
this.ampAxios.interceptors.response.use(response => response, options.onError);
|
|
86
|
+
}
|
|
82
87
|
this.retryStrategy = options.retryStrategy ?? noopRestRetryStrategy;
|
|
83
88
|
this.rateLimitStrategy = options.rateLimitStrategy ?? noopRestClientRateLimitStrategy;
|
|
84
89
|
this.baseUrl = options.baseUrl;
|
|
@@ -131,6 +136,7 @@ export const getAmpRestClient = (options: AmpRestClientOptions): RestClient => {
|
|
|
131
136
|
logger: options.logger,
|
|
132
137
|
client: options.client,
|
|
133
138
|
strict: _.isUndefined(options.strict) ? true : options.strict,
|
|
139
|
+
onError: options.onError,
|
|
134
140
|
});
|
|
135
141
|
return ampClient;
|
|
136
142
|
};
|