rest-client-sdk
Advanced tools
Comparing version 7.0.3 to 7.1.0
@@ -16,2 +16,3 @@ import Mapping from './Mapping'; | ||
loggerEnabled?: boolean; | ||
onRefreshTokenFailure?: (error: Error) => void; | ||
}; | ||
@@ -18,0 +19,0 @@ export default interface RestClientSdkInterface<M extends SdkMetadata> { |
{ | ||
"name": "rest-client-sdk", | ||
"version": "7.0.3", | ||
"version": "7.1.0", | ||
"description": "Rest Client SDK for API", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -122,2 +122,5 @@ # Rest Client JS SDK | ||
unitOfWorkEnabled: true, // if key is missing, UnitOfWork will be disabled by default | ||
onRefreshTokenFailure: () => { | ||
// do something when the refresh token fails | ||
}, | ||
}; // path and scheme are mandatory | ||
@@ -124,0 +127,0 @@ |
@@ -404,13 +404,26 @@ import URI from 'urijs'; | ||
): Promise<Response> { | ||
return this.#tokenStorage.refreshToken().then(() => { | ||
// eslint-disable-next-line prefer-const | ||
let { headers, ...rest } = requestParams; | ||
return this.#tokenStorage | ||
.refreshToken() | ||
.then(() => { | ||
// eslint-disable-next-line prefer-const | ||
let { headers, ...rest } = requestParams; | ||
const updatedRequestParams: RequestInit = { | ||
...rest, | ||
headers: removeAuthorization(headers), | ||
}; | ||
const updatedRequestParams: RequestInit = { | ||
...rest, | ||
headers: removeAuthorization(headers), | ||
}; | ||
return this._fetchWithToken(input, updatedRequestParams); | ||
}); | ||
return this._fetchWithToken(input, updatedRequestParams); | ||
}) | ||
.catch((e) => { | ||
if (e instanceof OauthError) { | ||
this.#tokenStorage.logout().then(() => { | ||
if (this.sdk.config.onRefreshTokenFailure) { | ||
this.sdk.config.onRefreshTokenFailure(e); | ||
} | ||
}); | ||
} | ||
throw e; | ||
}); | ||
} | ||
@@ -417,0 +430,0 @@ |
@@ -17,2 +17,3 @@ import Mapping from './Mapping'; | ||
loggerEnabled?: boolean; | ||
onRefreshTokenFailure?: (error: Error) => void; | ||
}; | ||
@@ -19,0 +20,0 @@ |
@@ -196,3 +196,3 @@ /* eslint-disable camelcase */ | ||
// throw error if response body is an oauth error | ||
manageOauthError(body, response); | ||
manageOauthError(body, originalResponse); | ||
} else if (response.status >= 400) { | ||
@@ -199,0 +199,0 @@ // throw an error if response status code is an "error" status code |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
604453
8127
406