Skip to content

Commit

Permalink
feat: add error handler for browser api response (#7)
Browse files Browse the repository at this point in the history
* feat: add error handler for browser api response
* fix: handle error rejection in requestAutoSignin
  • Loading branch information
HunnySajid authored May 10, 2024
1 parent 6e7344f commit 66ae493
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ const requestAutoSignin = async () => {
subtype: "auto-signin-signature",
});
if (error) {
window.postMessage({ type: "select-auto-signin", requestId }, "*");
pubsub.subscribe(requestId, (_event, data) => {
resolve(data);
pubsub.unsubscribe(requestId);
});
if (error.code === 404) {
window.postMessage({ type: "select-auto-signin", requestId }, "*");
pubsub.subscribe(requestId, (_event, data) => {
resolve(data);
pubsub.unsubscribe(requestId);
});
} else {
reject(error);
}
} else {
resolve(data);
}
Expand All @@ -105,11 +109,14 @@ const requestAutoSignin = async () => {
const signifyFetch = async (url, req, fetchHeaders = false, aidName = "") => {
if (fetchHeaders && aidName) {
if (canCallAsync()) {
const { data } = await chrome.runtime.sendMessage(extensionId, {
const { data, error } = await chrome.runtime.sendMessage(extensionId, {
type: "fetch-resource",
subtype: "signify-headers",
data: { aidName },
});
if (error && error.message) {
throw new Error(error.message);
}
req.headers = { ...(req.headers ?? {}), ...(data ?? {}) };
} else {
req.headers = {
Expand Down

0 comments on commit 66ae493

Please sign in to comment.