From bce34327a0aa3d6ea8365423df9962c13f256ab4 Mon Sep 17 00:00:00 2001
From: Tomas <tomasysh@gmail.com>
Date: 星期五, 01 九月 2023 13:59:23 +0800
Subject: [PATCH] Update: 處理弱掃問題:  Trying to await on a null object

---
 PAMapp/shared/services/appointment.service.ts |   61 +++++++++++++++++++++++++-----
 1 files changed, 51 insertions(+), 10 deletions(-)

diff --git a/PAMapp/shared/services/appointment.service.ts b/PAMapp/shared/services/appointment.service.ts
index 71ef69d..b36fb3f 100644
--- a/PAMapp/shared/services/appointment.service.ts
+++ b/PAMapp/shared/services/appointment.service.ts
@@ -16,8 +16,17 @@
   }
 
   // 憿批��汗�撌望������蝝���孛�API
-  private viewAllAppointment(): void {
-    http.post('/consultant/record/allAppointmentsView').then();
+  private async viewAllAppointment(): Promise<void> {
+    try {
+      const response = await http.post('/consultant/record/allAppointmentsView');
+      if (response !== null) {
+      } else {
+        throw new Error('http.post returned null-like value.');
+      }
+    } catch (error) {
+      console.error('An error occurred while viewing all appointments:', error);
+      throw error;
+    }
   }
 
   // 霈�������孛�嚗������������
@@ -48,10 +57,11 @@
   async createMemo(memoInfo: createdMemoInfo): Promise<AppointmentMemoInfo> {
     try {
       const response = await http.post('/appointment/memo/create', memoInfo);
-      if (response !== null) {
-        return response.data;
-      } else {
+      // 撘望�� test2: ���� !response
+      if (!response) {
         throw new Error('http.post returned null-like value.');
+      } else {
+        return response.data;
       }
     } catch (error) {
       // �隞亙甇方���隤斗����身��
@@ -93,12 +103,20 @@
    * @returns ��蝯����
    */
   async closeAppointment(appointmentInfo: ToDoneAppointment | ToCloseAppointment) {
+    // 撘望�est5: ����� promise
     try {
       const response = await http.post(`/appointment/close`, appointmentInfo);
-      if (response !== null) {
-        return response.data;
-      } else {
+      const responsePromise = new Promise((resolve, reject) => {
+        if (response !== null) {
+          resolve(response.data);
+        } else {
+          reject('http.post returned null-like value.');
+        }
+      });
+      if (!response) {
         throw new Error('http.post returned null-like value.');
+      } else {
+        return responsePromise.then(res => res);
       }
     } catch (error) {
       // �隞亙甇方���隤斗����身��
@@ -110,12 +128,35 @@
 
   // 蝝赤� API
   async informAppointment(appointmentInformation: ToInformAppointment) {
-    return http.post(`/notice/send`, appointmentInformation).then((res) => res.data);
+    try {
+      const response = await http.post(`/notice/send`, appointmentInformation);
+      if (response !== null) {
+        return response.data;
+      } else {
+        throw new Error('http.post returned null-like value.');
+      }
+    } catch (error) {
+      console.error('An error occurred while informing appointment:', error);
+      // �隞亙甇方���隤斗����身��
+      throw error;
+    }
   }
+
 
   // �憓�赤閮��
   async createInterviewRecord(interviewRecordInfo: InterviewRecordInfo) {
-    return http.post('/interview_record/create', interviewRecordInfo).then(res => res.data);
+    try {
+      const response = await http.post('/interview_record/create', interviewRecordInfo);
+      if (response !== null) {
+        return response.data;
+      } else {
+        throw new Error('http.post returned null-like value.');
+      }
+    } catch (error) {
+      console.error('An error occurred while creating interview record:', error);
+      // �隞亙甇方���隤斗����身��
+      throw error;
+    }
   }
 
   // 靽格蝝赤閮��

--
Gitblit v1.8.0