From 2a4aa9db00a4f8fdb71ce038664c9cf0d362d158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 7 Mar 2026 07:55:49 +0800 Subject: [PATCH] Add optional chaining to error.response.status in catch blocks Co-Authored-By: Claude Opus 4.6 --- src/stores/allMapData.ts | 4 ++-- src/stores/conformance.ts | 4 ++-- src/stores/files.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stores/allMapData.ts b/src/stores/allMapData.ts index 0ccba63..2927e7d 100644 --- a/src/stores/allMapData.ts +++ b/src/stores/allMapData.ts @@ -211,7 +211,7 @@ export const useAllMapDataStore = defineStore('allMapDataStore', { }); return this.allCase; } catch(error) { - if(error.response.status === 404) { + if(error.response?.status === 404) { this.infinite404 = 404; return; } @@ -250,7 +250,7 @@ export const useAllMapDataStore = defineStore('allMapDataStore', { }); return this.allBaseCase; } catch(error) { - if(error.response.status === 404) { + if(error.response?.status === 404) { this.infinite404 = 404; return; } diff --git a/src/stores/conformance.ts b/src/stores/conformance.ts index 65c5807..bc5e996 100644 --- a/src/stores/conformance.ts +++ b/src/stores/conformance.ts @@ -316,7 +316,7 @@ export const useConformanceStore = defineStore('conformanceStore', { this.allCases = response.data.cases; return response.data.cases; } catch(error) { - if(error.response.status === 404) { + if(error.response?.status === 404) { this.infinite404 = 404; return; } @@ -350,7 +350,7 @@ export const useConformanceStore = defineStore('conformanceStore', { this.allLoopCases = response.data.cases; return response.data.cases; } catch(error) { - if(error.response.status === 404) { + if(error.response?.status === 404) { this.infinite404 = 404; return; } diff --git a/src/stores/files.ts b/src/stores/files.ts index 2320002..a865b5c 100644 --- a/src/stores/files.ts +++ b/src/stores/files.ts @@ -155,7 +155,7 @@ export const useFilesStore = defineStore('filesStore', { this.$router.push({name: 'Upload'}); Swal.close(); // 關閉進度條 } catch(error) { - if(error.response.status === 422) { + if(error.response?.status === 422) { // msg: 'not in UTF-8' | 'insufficient columns' | 'the csv file is empty' | 'the filename does not ends with .csv' // type: 'encoding' | 'insufficient_columns' | 'empty' | 'name_suffix' const detail = error.response.data.detail; @@ -199,7 +199,7 @@ export const useFilesStore = defineStore('filesStore', { await uploadSuccess(); this.$router.push({name: 'Files'}); } catch(error) { - if(error.response.status === 422) { + if(error.response?.status === 422) { const detail = [...error.response.data.detail]; uploadFailedSecond(detail);