Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry token with background service before hard failing #177

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions addon/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export let sfConn = {
if (message) {
this.instanceHostname = getMyDomain(message.hostname);
this.sessionId = message.key;
localStorage.setItem(sfHost + "_" + ACCESS_TOKEN, message.key);
}
}
const IS_SANDBOX = "isSandbox";
Expand Down Expand Up @@ -102,15 +103,22 @@ export let sfConn = {
} else if (xhr.status == 401) {
let error = xhr.response.length > 0 ? xhr.response[0].message : "New access token needed";
sessionError = error;
//TODO check if login again but no token else modfy getSession when oldToken exists
//const ACCESS_TOKEN = "access_token";
//localStorage.getItem(sfHost + "_" + ACCESS_TOKEN);
//localStorage.removeItem(sfHost + "_" + ACCESS_TOKEN);
showInvalidTokenBanner();
let err = new Error();
err.name = "Unauthorized";
err.message = error;
throw err;
let message = await new Promise(resolve =>
chrome.runtime.sendMessage({message: "getSession", sfHost: this.instanceHostname}, resolve));
const ACCESS_TOKEN = "access_token";
let oldToken = localStorage.getItem(sfHost + "_" + ACCESS_TOKEN);
if (message && message.key && message.key != oldToken) {
this.instanceHostname = getMyDomain(message.hostname);
this.sessionId = message.key;
localStorage.setItem(sfHost + "_" + ACCESS_TOKEN, message.key);
return await this.rest(url, {logErrors, method, api, body, bodyType, responseType, headers, progressHandler, withoutCache: true});
} else {
showInvalidTokenBanner();
let err = new Error();
err.name = "Unauthorized";
err.message = error;
throw err;
}
} else if (xhr.status == 431) {
let err = new Error();
err.name = "Bad Message";
Expand Down