Advertisement
crutch12

Untitled

Feb 10th, 2021
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import type { SetupContext } from 'vue-demi';
  2. import { onErrorCaptured, getCurrentInstance } from 'vue-demi';
  3. import { useContext } from '@nuxtjs/composition-api';
  4.  
  5. /**
  6.  * Регистрация обработки глобальных ошибок, чтобы в development режиме автоматически не сваливаться в ошибку.
  7.  * @description - Но всегда есть возможность нажать кнопку "Выбросить ошибку"
  8.  */
  9. const preventErrorsInDevelopment = () => {
  10.   const vm = getCurrentInstance();
  11.  
  12.   const { error: showError } = useContext();
  13.   const { config: envConfig } = useConfig('env');
  14.  
  15.   onErrorCaptured((err: Error) => {
  16.     if (envConfig.NODE_ENV === 'development') {
  17.       console.error(err);
  18.  
  19.       vm?.$notify && vm.$notify.$error({
  20.         title: '!!! Произошла фатальная ошибка (всё сломалось, development режим включен), см. консоль !!!',
  21.         text: err.message,
  22.         modules: {
  23.           Buttons: {
  24.             sticker: true,
  25.           },
  26.           Confirm: {
  27.             confirm: true,
  28.             buttons: [
  29.               {
  30.                 text: 'Выбросить ошибку',
  31.                 click(notification: any) {
  32.                   console.error(err);
  33.                   showError(err);
  34.                   notification.close();
  35.                 },
  36.                 primary: true,
  37.               },
  38.             ],
  39.           },
  40.         },
  41.       });
  42.  
  43.       return false;
  44.     }
  45.   });
  46. };
  47.  
  48. // @NOTE: Setup function for whole application
  49. export const globalSetup = (ctx: SetupContext) => {
  50.   preventErrorsInDevelopment();
  51. };
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement