fix: throw error msg

This commit is contained in:
Gabe
2025-10-30 19:42:00 +08:00
parent e417c0106a
commit e83c1eb017
4 changed files with 10 additions and 30 deletions

View File

@@ -285,20 +285,11 @@ const messageHandlers = {
*/
browser.runtime.onMessage.addListener(async ({ action, args }) => {
const handler = messageHandlers[action];
if (!handler) {
const errorMessage = `Message action is unavailable: ${action}`;
kissLog("runtime onMessage", action, new Error(errorMessage));
return null;
throw new Error(`Message action is unavailable: ${action}`);
}
try {
const result = await handler(args);
return result;
} catch (err) {
kissLog("runtime onMessage", action, err);
return null;
}
return handler(args);
});
/**

View File

@@ -59,7 +59,7 @@ export function AlertProvider({ children }) {
onClose={handleClose}
anchorOrigin={{ vertical, horizontal }}
>
<Alert onClose={handleClose} severity={severity} sx={{ width: "100%" }}>
<Alert onClose={handleClose} severity={severity} sx={{ maxWidth: "80%" }}>
{message}
</Alert>
</Snackbar>

View File

@@ -41,6 +41,12 @@ export const fetchGM = async (
});
},
onerror: reject,
onabort: () => {
reject(new Error("GM request onabort."));
},
ontimeout: () => {
reject(new Error("GM request timeout."));
},
});
});

View File

@@ -77,24 +77,7 @@ function TestButton({ api }) {
alert.error(
<>
<div>{i18n("test_failed")}</div>
{msg === err.message ? (
<div
style={{
maxWidth: 400,
}}
>
{msg}
</div>
) : (
<pre
style={{
maxWidth: 400,
overflow: "auto",
}}
>
{msg}
</pre>
)}
{msg === err.message ? <div>{msg}</div> : <pre>{msg}</pre>}
</>
);
} finally {