Skip to content

Commit

Permalink
Merge pull request PrestaShop#435 from NeOMakinG/handle-errors
Browse files Browse the repository at this point in the history
Add global error handler
  • Loading branch information
Hlavtox authored Jan 18, 2023
2 parents 8b0e55e + 592a1e7 commit 9aa972c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/js/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import useToast from './components/useToast';

const initErrorHandler = () => {
const {Theme: {events}} = window;
const {prestashop} = window;

prestashop.on(events.handleError, ({resp}: {resp: {errors: string[]}}) => {
resp.errors.forEach((error) => {
useToast(error, {type: 'danger'}).show();
});
});
};

export default initErrorHandler;
2 changes: 2 additions & 0 deletions src/js/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import initSearchbar from './modules/ps_searchbar';
import initLanguageSelector from './modules/ps_languageselector';
import initCurrencySelector from './modules/ps_currencyselector';
import initVisiblePassword from './visible-password';
import initErrorHandler from './errors';
import useToast from './components/useToast';
import useAlert from './components/useAlert';
import usePasswordPolicy from './components/usePasswordPolicy';
Expand Down Expand Up @@ -51,6 +52,7 @@ $(() => {
initVisiblePassword();
initDesktopMenu();
initFormValidation();
initErrorHandler();
usePasswordPolicy('.field-password-policy');

prestashop.on(events.responsiveUpdate, () => {
Expand Down

0 comments on commit 9aa972c

Please sign in to comment.