Inertia: Bug: Cannot read property 'status' of undefined

Created on 12 Mar 2020  路  5Comments  路  Source: inertiajs/inertia

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

In that case the error.response is null.
https://github.com/inertiajs/inertia/blob/70b6bda4f23061558d48f91a95baaa9062b9e0bb/src/inertia.js#L83

Suggestion before line 83:

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

Most helpful comment

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. 馃憤

All 5 comments

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();
});

+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

+1 Same here

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. 馃憤

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()
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

philippkuehn picture philippkuehn  路  3Comments

piercemcgeough picture piercemcgeough  路  4Comments

reinink picture reinink  路  5Comments

jalt007 picture jalt007  路  4Comments

TimVanHerwijnen picture TimVanHerwijnen  路  5Comments