Make the message optional

This commit is contained in:
Manav Rathi
2024-11-05 14:11:25 +05:30
parent a048f1a38f
commit 1dd45a2e04
4 changed files with 12 additions and 6 deletions

View File

@@ -87,7 +87,7 @@ const ModifyMapSettings = ({ open, onClose, onRootClose, mapEnabled }) => {
await updateMapEnabled(false);
handleClose();
} catch (e) {
log.error("Error", e);
log.error(e);
setPhase("failed");
}
};
@@ -98,7 +98,7 @@ const ModifyMapSettings = ({ open, onClose, onRootClose, mapEnabled }) => {
await updateMapEnabled(true);
handleClose();
} catch (e) {
log.error("Error", e);
log.error(e);
setPhase("failed");
}
};

View File

@@ -225,7 +225,7 @@ export default function App({ Component, pageProps }: AppProps) {
);
const onGenericError = useCallback((e: unknown) => {
log.error("Error", e);
log.error(e);
showMiniDialog(genericErrorDialogAttributes());
}, []);

View File

@@ -174,7 +174,7 @@ export const AttributedMiniDialog: React.FC<
await attributes.continue?.action?.();
resetPhaseAndClose();
} catch (e) {
log.error("Error", e);
log.error(e);
setPhase("failed");
}
}}

View File

@@ -65,8 +65,11 @@ const messageWithError = (message: string, e?: unknown) => {
return `${message}: ${es}`;
};
const logError = (message: string, e?: unknown) => {
const m = `[error] ${messageWithError(message, e)}`;
const logError = (message: unknown, e?: unknown) => {
const m =
typeof message == "string"
? `[error] ${messageWithError(message, e)}`
: `[error] ${messageWithError("Error", message)}`;
console.error(m);
if (shouldLogToDisk) logToDisk(m);
};
@@ -128,6 +131,9 @@ export default {
* any arbitrary object that we obtain, say, when in a try-catch handler (in
* JavaScript any arbitrary value can be thrown).
*
* If only one argument is specified, and it is not a string, then it is
* taken as the error to be printed, paired with a generic message.
*
* The log is written to disk and printed to the browser console.
*/
error: logError,