mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
25 lines
991 B
TypeScript
25 lines
991 B
TypeScript
import { ScriptDeath } from "./Netscript/ScriptDeath";
|
|
import { helpers } from "./Netscript/NetscriptHelpers";
|
|
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
|
|
|
export function setupUncaughtPromiseHandler(): void {
|
|
window.addEventListener("unhandledrejection", function (e) {
|
|
if (helpers.isScriptErrorMessage(e.reason)) {
|
|
const errorTextArray = e.reason.split("|DELIMITER|");
|
|
const hostname = errorTextArray[1];
|
|
const scriptName = errorTextArray[2];
|
|
const errorMsg = errorTextArray[3];
|
|
|
|
let msg = `UNCAUGHT PROMISE ERROR<br>You forgot to await a promise<br>${scriptName}@${hostname}<br>`;
|
|
msg += "<br>";
|
|
msg += errorMsg;
|
|
dialogBoxCreate(msg);
|
|
} else if (e.reason instanceof ScriptDeath) {
|
|
const msg =
|
|
`UNCAUGHT PROMISE ERROR<br>You forgot to await a promise<br>${e.reason.name}@${e.reason.hostname} (PID - ${e.reason.pid})<br>` +
|
|
`Maybe hack / grow / weaken ?`;
|
|
dialogBoxCreate(msg);
|
|
}
|
|
});
|
|
}
|