From 171f6a2b59ebb694ec448331f135c137b8931834 Mon Sep 17 00:00:00 2001 From: Anton Tranelis <31516529+antontranelis@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:47:09 +0200 Subject: [PATCH] fix: prevent 'Cannot read properties of undefined (reading '0')' errors (#385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add proper array length checks before accessing error.errors[0] - Secure error handling in App.tsx for both map loading and layer loading - Fix unsafe array access in mapApi.ts error handler - Prevent crashes when error.errors is undefined or empty array 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude --- app/src/App.tsx | 4 ++-- app/src/api/mapApi.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/App.tsx b/app/src/App.tsx index 354d216e..033d786c 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -117,7 +117,7 @@ function App() { setError( typeof error === 'string' ? error - : error?.errors?.[0]?.message || + : (error?.errors?.length > 0 ? error.errors[0]?.message : null) || error?.message || 'Failed to connect to the server. Please check your connection and try again.', ) @@ -158,7 +158,7 @@ function App() { setError( typeof error === 'string' ? error - : error?.errors?.[0]?.message || + : (error?.errors?.length > 0 ? error.errors[0]?.message : null) || error?.message || 'Failed to load map layers. Please check your permissions and try again.', ) diff --git a/app/src/api/mapApi.ts b/app/src/api/mapApi.ts index 2a5f0523..d4a2da67 100644 --- a/app/src/api/mapApi.ts +++ b/app/src/api/mapApi.ts @@ -26,7 +26,7 @@ export class mapApi { else return 'null' } catch (error: any) { console.log(error) - if (error.errors[0]?.message) throw error.errors[0].message + if (error.errors?.length > 0 && error.errors[0]?.message) throw error.errors[0].message else throw error } }