fix: prevent 'Cannot read properties of undefined (reading '0')' errors

- 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 <noreply@anthropic.com>
This commit is contained in:
Anton Tranelis 2025-09-13 10:51:20 +02:00
parent 767f7a0197
commit db87cd745e
2 changed files with 3 additions and 3 deletions

View File

@ -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.',
)

View File

@ -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
}
}