diff --git a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js index 9c0a8363545..97217d344a9 100644 --- a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js @@ -8,8 +8,7 @@ odoo.define('point_of_sale.PaymentScreen', function (require) { const { useListener } = require('web.custom_hooks'); const Registries = require('point_of_sale.Registries'); const { onChangeOrder } = require('point_of_sale.custom_hooks'); - const { identifyError } = require('point_of_sale.utils'); - const { ConnectionLostError, ConnectionAbortedError } = require('@web/core/network/rpc_service'); + const { isConnectionError } = require('point_of_sale.utils'); class PaymentScreen extends PosComponent { constructor() { @@ -205,11 +204,7 @@ odoo.define('point_of_sale.PaymentScreen', function (require) { await this._handlePushOrderError(error); } else { // We don't block for connection error. But we rethrow for any other errors. - const errorIdentity = identifyError(error); - if ( - errorIdentity instanceof ConnectionLostError || - errorIdentity instanceof ConnectionAbortedError - ) { + if (isConnectionError(error)) { this.showPopup('OfflineErrorPopup', { title: this.env._t('Connection Error'), body: this.env._t('Order is not synced. Check your internet connection'), diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js index f93ff87ece3..c1522915bfe 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js @@ -8,7 +8,7 @@ odoo.define('point_of_sale.ProductScreen', function(require) { const Registries = require('point_of_sale.Registries'); const { onChangeOrder, useBarcodeReader } = require('point_of_sale.custom_hooks'); const { Gui } = require('point_of_sale.Gui'); - const { isRpcError } = require('point_of_sale.utils'); + const { isConnectionError } = require('point_of_sale.utils'); const { useState, onMounted } = owl.hooks; const { parse } = require('web.field_utils'); @@ -225,7 +225,7 @@ odoo.define('point_of_sale.ProductScreen', function(require) { context: this.env.session.user_context, }); } catch (error) { - if (isRpcError(error) && error.message.code < 0) { + if (isConnectionError(error)) { return this.showPopup('OfflineErrorPopup', { title: this.env._t('Network Error'), body: this.env._t("Product is not loaded. Tried loading the product from the server but there is a network error."), diff --git a/addons/point_of_sale/static/src/js/Screens/TicketScreen/ControlButtons/InvoiceButton.js b/addons/point_of_sale/static/src/js/Screens/TicketScreen/ControlButtons/InvoiceButton.js index c6e47c385e5..a1caf97cd6e 100644 --- a/addons/point_of_sale/static/src/js/Screens/TicketScreen/ControlButtons/InvoiceButton.js +++ b/addons/point_of_sale/static/src/js/Screens/TicketScreen/ControlButtons/InvoiceButton.js @@ -2,7 +2,7 @@ odoo.define('point_of_sale.InvoiceButton', function (require) { 'use strict'; const { useListener } = require('web.custom_hooks'); - const { isRpcError } = require('point_of_sale.utils'); + const { isConnectionError } = require('point_of_sale.utils'); const PosComponent = require('point_of_sale.PosComponent'); const Registries = require('point_of_sale.Registries'); @@ -119,7 +119,7 @@ odoo.define('point_of_sale.InvoiceButton', function (require) { try { await this._invoiceOrder(); } catch (error) { - if (isRpcError(error) && error.message.code < 0) { + if (isConnectionError(error)) { this.showPopup('ErrorPopup', { title: this.env._t('Network Error'), body: this.env._t('Unable to invoice order.'), diff --git a/addons/point_of_sale/static/src/js/utils.js b/addons/point_of_sale/static/src/js/utils.js index 6ac1ec88f73..d0f2deedf5f 100644 --- a/addons/point_of_sale/static/src/js/utils.js +++ b/addons/point_of_sale/static/src/js/utils.js @@ -2,7 +2,7 @@ odoo.define('point_of_sale.utils', function (require) { 'use strict'; const { EventBus } = owl.core; - const { ConnectionAbortedError } = require('@web/core/network/rpc_service'); + const { ConnectionAbortedError, ConnectionLostError } = require('@web/core/network/rpc_service'); function getFileAsText(file) { return new Promise((resolve, reject) => { @@ -38,12 +38,9 @@ odoo.define('point_of_sale.utils', function (require) { }); }; - function isRpcError(error) { - return ( - !(error instanceof Error) && - error.message && - [100, 200, 404, -32098].includes(error.message.code) - ); + function isConnectionError(error) { + const _error = identifyError(error); + return _error instanceof ConnectionAbortedError || _error instanceof ConnectionLostError; } function identifyError(error) { @@ -65,5 +62,5 @@ odoo.define('point_of_sale.utils', function (require) { return errorToHandle || error; } - return { getFileAsText, nextFrame, isRpcError, posbus: new EventBus(), identifyError }; + return { getFileAsText, nextFrame, posbus: new EventBus(), identifyError, isConnectionError }; }); diff --git a/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderFetcher.js b/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderFetcher.js index aac4119fd3a..016231aea14 100644 --- a/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderFetcher.js +++ b/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderFetcher.js @@ -3,7 +3,7 @@ odoo.define('pos_sale.SaleOrderFetcher', function (require) { const { EventBus } = owl.core; const { Gui } = require('point_of_sale.Gui'); - const { isRpcError } = require('point_of_sale.utils'); + const { isConnectionError } = require('point_of_sale.utils'); const models = require('point_of_sale.models'); class SaleOrderFetcher extends EventBus { @@ -53,7 +53,7 @@ odoo.define('pos_sale.SaleOrderFetcher', function (require) { this.trigger('update'); } catch (error) { - if (isRpcError(error) && error.message.code < 0) { + if (isConnectionError(error)) { Gui.showPopup('ErrorPopup', { title: this.comp.env._t('Network Error'), body: this.comp.env._t('Unable to fetch orders if offline.'), diff --git a/addons/pos_sale/static/src/js/SetSaleOrderButton.js b/addons/pos_sale/static/src/js/SetSaleOrderButton.js index 5a8ac15a61d..12bf6b0fb61 100644 --- a/addons/pos_sale/static/src/js/SetSaleOrderButton.js +++ b/addons/pos_sale/static/src/js/SetSaleOrderButton.js @@ -5,7 +5,7 @@ odoo.define('pos_sale.SetSaleOrderButton', function(require) { const ProductScreen = require('point_of_sale.ProductScreen'); const { useListener } = require('web.custom_hooks'); const Registries = require('point_of_sale.Registries'); - const { isRpcError } = require('point_of_sale.utils'); + const { isConnectionError } = require('point_of_sale.utils'); class SetSaleOrderButton extends PosComponent { constructor() { @@ -34,7 +34,7 @@ odoo.define('pos_sale.SetSaleOrderButton', function(require) { }); this.showScreen('SaleOrderManagementScreen'); } catch (error) { - if (isRpcError(error) && error.message.code < 0) { + if (isConnectionError(error)) { this.showPopup('ErrorPopup', { title: this.env._t('Network Error'), body: this.env._t('Cannot access order management screen if offline.'),