From 078cdb2b41d1dec47e2d981c2d2e618d12beddb4 Mon Sep 17 00:00:00 2001
From: Mila <Mila@pollex.com.tw>
Date: 星期四, 26 十二月 2024 09:43:23 +0800
Subject: [PATCH] feat(顧問登入): 串接 otp 發送/驗證 api

---
 PAMapp/shared/services/httpClient.ts |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/PAMapp/shared/services/httpClient.ts b/PAMapp/shared/services/httpClient.ts
index bafed6e..8fe7bad 100644
--- a/PAMapp/shared/services/httpClient.ts
+++ b/PAMapp/shared/services/httpClient.ts
@@ -1,18 +1,30 @@
-import { AxiosRequestConfig, AxiosError, AxiosResponse} from 'axios';
-import axios from 'axios';
-import _ from 'lodash';
+import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
 
 import messageBoxService from './message-box.service';
 
 const notRequireInterceptorErrorUrl = [
   '/otp/verify',
+  // '/otp/sendOtp',
   '/eService/authenticate',
   '/login/validate/get_img_code',
   '/login/validate/verify_img_code',
+  '/api/access_analysis/insert'
 ];
 
+function getBaseUrl(): string {
+  const baseUrl = process.env.BASE_URL;
+  if (!baseUrl) {
+    throw new Error('BASE_URL is not defined in process.env');
+  }
+  // const pattern = /^(https?:\/\/)[\w.-]+(:\d+)?/i; // �����RL撽��
+  // if (!pattern.test(baseUrl)) {
+  //   throw new Error('Invalid BASE_URL');
+  // }
+  // 銝�閬���RL嚗�摰歇蝬蝯�RL
+  return baseUrl;
+}
 export const http = axios.create({
-  baseURL: process.env.BASE_URL,
+  baseURL: getBaseUrl(), // 雿輻�������aseURL
   withCredentials: true
 });
 
@@ -47,7 +59,8 @@
 
 function addHttpHeader(config: AxiosRequestConfig): void {
   config.headers = {
-    Authorization: 'Bearer ' + localStorage.getItem('id_token')
+    Authorization: 'Bearer ' + localStorage.getItem('id_token'),
+    'content-type': 'application/json'
   }
 }
 
@@ -64,13 +77,22 @@
 };
 
 function showErrorMessageBox(error: any): void {
-  // console.log('error', error, error.response);
   setTimeout(() => {
-    if (!_.includes(notRequireInterceptorErrorUrl, error.config.url)) {
+    // NOTE: 甇斤 HOT FIX 憿批��憭望������暹��� dialog [Tomas, 2022/7/20 14:21]
+    if(error.config.url.includes('/eService/authenticate')) return;
+    if (error.config.url.includes('/otp/sendOtp')) {
+      messageBoxService.showErrorMessage('', error);
+      return
+    }
+    if (!notRequireInterceptorErrorUrl.includes(error.config.url)) {
       switch (error.response.status) {
         case 401:
           Promise.all([messageBoxService.showErrorMessage('���暹��'), window.$nuxt.$store.dispatch('localStorage/actionStorageClear')]).then(() => {
-            _.isEqual(window.$nuxt.$route.name, 'index') ? location.reload() : window.$nuxt.$router.push('/');
+            if (window.$nuxt.$route.name === 'index') {
+              location.reload();
+            } else {
+              window.$nuxt.$router.push('/');
+            }
           });
           break;
 

--
Gitblit v1.8.0