rest-client-sdk 7.0.3 → 7.1.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.
package/README.md CHANGED
@@ -119,6 +119,9 @@ const config = {
119
119
  authorizationType: 'Bearer', // default to "Bearer", but can be "Basic" or anything
120
120
  useDefaultParameters: true,
121
121
  unitOfWorkEnabled: true, // if key is missing, UnitOfWork will be disabled by default
122
+ onRefreshTokenFailure: () => {
123
+ // do something when the refresh token fails
124
+ },
122
125
  }; // path and scheme are mandatory
123
126
 
124
127
  const sdk = new RestClientSdk(tokenStorage, config, mapping);
package/dist/index.es.js CHANGED
@@ -1326,6 +1326,16 @@ var AbstractClient = /*#__PURE__*/function () {
1326
1326
  });
1327
1327
 
1328
1328
  return _this4._fetchWithToken(input, updatedRequestParams);
1329
+ })["catch"](function (e) {
1330
+ if (e instanceof OauthError) {
1331
+ _classPrivateFieldGet(_this4, _tokenStorage).logout().then(function () {
1332
+ if (_this4.sdk.config.onRefreshTokenFailure) {
1333
+ _this4.sdk.config.onRefreshTokenFailure(e);
1334
+ }
1335
+ });
1336
+ }
1337
+
1338
+ throw e;
1329
1339
  });
1330
1340
  }
1331
1341
  }, {
@@ -2945,7 +2955,7 @@ var TokenStorage = /*#__PURE__*/function () {
2945
2955
  return response.json().then(function (body) {
2946
2956
  if (isOauthError(body)) {
2947
2957
  // throw error if response body is an oauth error
2948
- manageOauthError(body, response);
2958
+ manageOauthError(body, originalResponse);
2949
2959
  } else if (response.status >= 400) {
2950
2960
  // throw an error if response status code is an "error" status code
2951
2961
  throw getHttpErrorFromResponse(originalResponse);