| 1 |
import { registry } from "@web/core/registry"; |
| 2 |
import { odooExceptionTitleMap, ErrorDialog } from "@web/core/errors/error_dialogs"; |
| 3 |
import { ConnectionLostError, RPCError } from "@web/core/network/rpc"; |
| 4 |
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; |
| 5 |
import { _t } from "@web/core/l10n/translation"; |
| 6 |
|
| 7 |
export function handleRPCError(error, dialog) { |
| 8 |
const { data } = error; |
| 9 |
if (odooExceptionTitleMap.has(error.exceptionName)) { |
| 10 |
const title = odooExceptionTitleMap.get(error.exceptionName).toString(); |
| 11 |
dialog.add(AlertDialog, { title, body: data.message }); |
| 12 |
} else { |
| 13 |
if (odoo.debug === "assets") { |
| 14 |
dialog.add(ErrorDialog, { |
| 15 |
traceback: data.message + "\n" + data.debug + "\n", |
| 16 |
}); |
| 17 |
} else { |
| 18 |
dialog.add(AlertDialog, { |
| 19 |
title: _t("Odoo Server Error"), |
| 20 |
body: data.message, |
| 21 |
}); |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
function rpcErrorHandler(env, error, originalError) { |
| 27 |
if (originalError instanceof RPCError) { |
| 28 |
handleRPCError(originalError, env.services.dialog); |
| 29 |
return true; |
| 30 |
} |
| 31 |
} |
| 32 |
registry.category("error_handlers").add("pos-rpcErrorHandler", rpcErrorHandler); |
| 33 |
|
| 34 |
export function offlineErrorHandler(env, error, originalError) { |
| 35 |
if (originalError instanceof ConnectionLostError) { |
| 36 |
if (!env.services.pos.data.network.warningTriggered) { |
| 37 |
env.services.dialog.add(AlertDialog, { |
| 38 |
title: _t("Connection Lost"), |
| 39 |
body: _t( |
| 40 |
"Until the connection is reestablished, Odoo Point of Sale will operate with limited functionality." |
| 41 |
), |
| 42 |
confirmLabel: _t("Continue with limited functionality"), |
| 43 |
}); |
| 44 |
env.services.pos.data.network.warningTriggered = true; |
| 45 |
} |
| 46 |
|
| 47 |
return true; |
| 48 |
} |
| 49 |
} |
| 50 |
registry.category("error_handlers").add("pos-offlineErrorHandler", offlineErrorHandler); |
| 51 |
|
| 52 |
function defaultErrorHandler(env, error, originalError) { |
| 53 |
if (error instanceof Error) { |
| 54 |
env.services.dialog.add(ErrorDialog, { |
| 55 |
traceback: error.traceback, |
| 56 |
}); |
| 57 |
} else { |
| 58 |
env.services.dialog.add(AlertDialog, { |
| 59 |
title: _t("Unknown Error"), |
| 60 |
body: _t("Unable to show information about this error."), |
| 61 |
showReloadButton: true, |
| 62 |
}); |
| 63 |
} |
| 64 |
return true; |
| 65 |
} |
| 66 |
registry |
| 67 |
.category("error_handlers") |
| 68 |
.add("pos-defaultErrorHandler", defaultErrorHandler, { sequence: 99 }); |