Skip to content

Commit

Permalink
refactor: type cast error instead of conditional check
Browse files Browse the repository at this point in the history
  • Loading branch information
juskek committed Jul 21, 2023
1 parent 2d42293 commit d998849
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
20 changes: 9 additions & 11 deletions src/background/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ chrome.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
try {
await chrome.debugger.detach({ tabId: tabId });
} catch (e: unknown) {
if (e instanceof Error) {
if (
e.message ===
`Debugger is not attached to the tab with id: ${tabId}.`
) {
console.warn(
`Tried to detach debugger from tab (tabId: ${tabId}) when there was none attached. `
);
return;
}
throw e;
const error = e as Error;
if (
error.message ===
`Debugger is not attached to the tab with id: ${tabId}.`
) {
console.warn(
`Tried to detach debugger from tab (tabId: ${tabId}) when there was none attached. `
);
return;
}
throw e;
}
Expand Down
18 changes: 9 additions & 9 deletions src/background/backgroundHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export const addBytesTransferred = async (bytes: number) => {
},
});
} catch (e: unknown) {
if (e instanceof Error) {
if (
e.message ===
"Could not establish connection. Receiving end does not exist."
) {
console.warn(
`Error Caught: ${e}\nIf popup is open and this error is seen in the console, debugging is required.`
);
}
const error = e as Error;

if (
error.message ===
"Could not establish connection. Receiving end does not exist."
) {
console.warn(
`Error Caught: ${e}\nIf popup is open and this error is seen in the console, debugging is required.`
);
} else {
throw e;
}
Expand Down

0 comments on commit d998849

Please sign in to comment.