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

View File

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

View File

@@ -41,6 +41,12 @@ export const fetchGM = async (
}); });
}, },
onerror: reject, 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( alert.error(
<> <>
<div>{i18n("test_failed")}</div> <div>{i18n("test_failed")}</div>
{msg === err.message ? ( {msg === err.message ? <div>{msg}</div> : <pre>{msg}</pre>}
<div
style={{
maxWidth: 400,
}}
>
{msg}
</div>
) : (
<pre
style={{
maxWidth: 400,
overflow: "auto",
}}
>
{msg}
</pre>
)}
</> </>
); );
} finally { } finally {