-
Notifications
You must be signed in to change notification settings - Fork 34
Description
- Laravel Version: 10.49.1
- Nova Version: 4.35.11
- PHP Version: 8.3.28
- Database Driver & Version: MariaDB 10.5.9
- Operating System and Version: macOS Darwin 24.0.0
- Browser type and version: Chrome 142.0.7444.176 (Official Build) (arm64)
- Reproduction Repository: not available (private commercial codebase)
Description:
I was building a feature that allows users to embed content using oEmbed into WordPress content. The iframe that WordPress generates doesn't allow for same origin network access (restrictive sandbox attribute). Under this condition, axios requests all create the same error: a destructuring error due to the lack of a defined response object inside the error interceptor function. The patch described below addresses the lack of a response object, thus allowing the actual error (whatever it is) to bubble up to the console.
File: vendor/laravel/nova/resources/js/util/axios.js
Current code (lines 18-28):
const response = error.response
const {
status,
data: { redirect },
} = response
// Show the user a 500 error
if (status >= 500) {Fixed code:
const response = error.response
// Handle network errors where response is undefined (e.g., CORS blocks, cross-origin
iframe cookie issues)
if (!response) {
return Promise.reject(error)
}
const {
status,
data: { redirect },
} = response
// Show the user a 500 error
if (status >= 500) {Fix: Handle undefined response in axios error interceptor
When a network error occurs (CORS block, DNS failure, cross-origin iframe without
proper sandbox permissions), axios returns an error where error.response is undefined.
The current interceptor attempts to destructure response without checking if it
exists, causing a crash:
TypeError: Cannot destructure property 'status' of 't' as it is undefined
This fix adds an early return for network errors, allowing the rejection to propagate
normally without crashing. This is consistent with how axios handles cancellations
(line 14-16) and matches axios best practices for error handling.