// src/boot/error-handler.ts
import { boot } from 'quasar/wrappers';
import { Router } from 'vue-router';
import { App } from 'vue';

export default boot(({ app, router }: { app: App<Element>; router: Router }) => {
  document.documentElement.lang='ja-JP';
  app.config.errorHandler = (err: any, instance: any, info: string) => {
    if (err.response && err.response.status === 401) {
      // 認証エラーの場合再ログインする
      console.error('(; ﾟДﾟ)/認証エラー(401)：', err, info);
      localStorage.removeItem('token');
      router.replace({
        path:'/login',
        query:{redirect:router.currentRoute.value.fullPath}
      });
    } else {
      console.error('(; ﾟДﾟ)例外：', err, info);
    }
  };
});
