Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Cannot read property 'status' of undefined #127

Closed
mpskovvang opened this issue Mar 12, 2020 · 5 comments
Closed

Bug: Cannot read property 'status' of undefined #127

mpskovvang opened this issue Mar 12, 2020 · 5 comments

Comments

@mpskovvang
Copy link

mpskovvang commented Mar 12, 2020

Inertia doesn't handle cases when a request fails without a response (e.g. no network).

In that case the error.response is null.

} else if (error.response.status === 409 && error.response.headers['x-inertia-location']) {

Suggestion before line 83:

} else if (!error.response) {
    Progress.stop()
     // Should the user be notified somehow?
}
@mpskovvang
Copy link
Author

mpskovvang commented Mar 12, 2020

Perhaps an API to catch errors would be a great addition. With an interception API you would be able to catch no network errors etc. 🙂

let api = Inertia.init(...);

api.interceptors.response.use((response) => response, (error) => {
  // whatever you want to do with the error
});

It might even solve the highly requested feature: custom progress bar?

api.interceptors.request.use((config) => {
    MyProgress.start()
    return config;
});

api.interceptors.response.use((response) => {
    MyProgress.done()
    return response;
}, (error) => {
    MyProgress.fail();
});

@liorocks
Copy link

liorocks commented Apr 7, 2020

+1 for that. I would really love to see the solution for this.

I'm getting this error in Sentry very often.

Screenshot at Apr 07 14-52-31

@mckenziearts
Copy link

+1 Same here

@reinink
Copy link
Member

reinink commented May 12, 2020

Thanks for reporting this. I agree, we need a better solution here. I plan to get back into some serious Inertia development in June, and I'll try and tackle this at that time. 👍

@reinink
Copy link
Member

reinink commented Oct 2, 2020

So I believe this has been corrected now. In the event that there is no response, the promise will simply fail, without causing another error.

image

Plus, you can now catch these errors using the new event system:

import { Inertia } from '@inertiajs/inertia'

Inertia.on('error', event => {
  console.log(`An unexpected error occurred during an Inertia visit.`)
  console.log(event.detail.error)

  // Prevent the error from being thrown
  event.preventDefault()
})

@reinink reinink closed this as completed Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants