diff --git a/Signum.React/Scripts/Globals.ts b/Signum.React/Scripts/Globals.ts index 8a52a88491..732881388b 100644 --- a/Signum.React/Scripts/Globals.ts +++ b/Signum.React/Scripts/Globals.ts @@ -4,10 +4,6 @@ declare global { escape(s: string): string; } - interface Promise { - done(this: Promise): void; - } - interface Window { __allowNavigatorWithoutUser?: boolean; __baseUrl: string; @@ -906,10 +902,6 @@ String.prototype.repeat = function (this: string, n: number) { return result; }; -Promise.prototype.done = function () { - this.catch(error => setTimeout(() => { throw error; }, 0)); -}; - export module Dic { var simplesTypes = ["number", "boolean", "string"]; diff --git a/Signum.React/Scripts/Modals/ErrorModal.tsx b/Signum.React/Scripts/Modals/ErrorModal.tsx index 7cddc49a1d..ea85b04b8a 100644 --- a/Signum.React/Scripts/Modals/ErrorModal.tsx +++ b/Signum.React/Scripts/Modals/ErrorModal.tsx @@ -103,6 +103,14 @@ export default function ErrorModal(p: ErrorModalProps) { ErrorModal.register = () => { + window.onunhandledrejection = p => { + var error = p.reason; + if (Modals.isStarted()) + ErrorModal.showErrorModal(error).done(); + else + console.error("Unhandled promise rejection:", error); + }; + var oldOnError = window.onerror; window.onerror = (message: Event | string, filename?: string, lineno?: number, colno?: number, error?: Error) => { diff --git a/Signum.React/Scripts/Services.ts b/Signum.React/Scripts/Services.ts index 79d347ebce..d232abc617 100644 --- a/Signum.React/Scripts/Services.ts +++ b/Signum.React/Scripts/Services.ts @@ -131,8 +131,8 @@ export function wrapRequest(options: AjaxOptions, makeCall: () => Promise a != "Framework").ToArray(); new CodeUpgradeRunner(autoDiscover: true).Run(uctx); } diff --git a/Signum.Upgrade/Upgrades/Upgrade_20220805_DoneIsDone.cs b/Signum.Upgrade/Upgrades/Upgrade_20220805_DoneIsDone.cs new file mode 100644 index 0000000000..7712d99c60 --- /dev/null +++ b/Signum.Upgrade/Upgrades/Upgrade_20220805_DoneIsDone.cs @@ -0,0 +1,15 @@ +namespace Signum.Upgrade.Upgrades; + +class Upgrade_20220805_DoneIsDone : CodeUpgradeBase +{ + public override string Description => "Remove .done() (rejectionhandled does it)"; + + public static Regex DoneRegex = new Regex(@"\s*\.done\(\)"); + public override void Execute(UpgradeContext uctx) + { + uctx.ForeachCodeFile(@"*.tsx, *.ts", file => + { + file.Replace(DoneRegex, ""); + }); + } +}