mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-12 23:36:00 +00:00
fix: prevent 'Cannot read properties of undefined (reading '0')' errors (#385)
- 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:
parent
6d504fa2e3
commit
171f6a2b59
@ -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.',
|
||||
)
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user