Conversation
| // 401 error code is hidden in error message and incorrectly reported as HTTP 500 error causing the refresh token | ||
| // callback not to be called | ||
| // Extract specific error code if possible | ||
| if (errorCode == "SOP-330007" && errorMessage && errorMessage.indexOf("XSV-350114") != -1 && errorMessage.indexOf(" 401") != -1) { |
There was a problem hiding this comment.
I guess the space character before 401 is there on purpose, maybe we could encode it (\u0020) to prevent any unwanted removal.
There was a problem hiding this comment.
Optionally comparisons can be made strong with ===
| // 401 error code is hidden in error message and incorrectly reported as HTTP 500 error causing the refresh token | ||
| // callback not to be called | ||
| // Extract specific error code if possible | ||
| if (errorCode == "SOP-330007" && errorMessage && errorMessage.indexOf("XSV-350114") != -1 && errorMessage.indexOf(" 401") != -1) { |
There was a problem hiding this comment.
Use a const for SOP-330007 as IMS_TOKEN_EXPIRY_CODE and then we can add it to comparison.
Create a separate function to check if it is a token expiry errorMessage. The function will take the errorMessage, check for null and other validations. It'll return true/false based on that.
There was a problem hiding this comment.
`// Define constants for error codes
const IMS_TOKEN_EXPIRY_CODE = "SOP-330007";
const TOKEN_EXPIRED_IDENTIFIER = "XSV-350114";
const UNAUTHORIZED_CODE = " 401";
function isTokenExpiryError(errorMessage) {
if (!errorMessage) {
return false; // Return false if errorMessage is null or undefined
}
return errorMessage.includes(TOKEN_EXPIRED_IDENTIFIER) && errorMessage.includes(UNAUTHORIZED_CODE);
}
// Main logic
if (errorCode === IMS_TOKEN_EXPIRY_CODE && isTokenExpiryError(errorMessage)) {
// Handle token expiry logic here
}
`
| try { | ||
| const jwt = Util.decodeJwtToken(call._bearerToken); | ||
| if (jwt) { | ||
| const createdAt = +jwt.created_at; |
There was a problem hiding this comment.
I hope this time is in milliseconds as Date.now is in milliseconds.
| const jwt = Util.decodeJwtToken(call._bearerToken); | ||
| if (jwt) { | ||
| const createdAt = +jwt.created_at; | ||
| const expiresIn = +jwt.expires_in; |
There was a problem hiding this comment.
Can we create a small helper method to check if JWT is expired just to divide the responsibility of the method
| try { | ||
| const base64Url = parts[1]; | ||
| const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); | ||
| const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) { |
There was a problem hiding this comment.
atob and btoa won't work in NodeJS server I think
Description
According to the documentation, the refreshClient function should be called when the ACC session expires due to token expiration. This allows the client to refresh the token and retry the failed SOAP call.
When the token expires, the refresh callback never called, and the sdk returns a 500 Internal Server Error.
Related Issue
#108
How Has This Been Tested?
New unit tests
Types of changes
Checklist: