#Unable to handle unreachable server with onError or trycatch

1 messages · Page 1 of 1 (latest)

tropic osprey
#

How do I handle server being down/unreachable when using router.visit? I tried onError and try catch but those didn't help. Maybe there's a way to get into that axios promise? 🤔

const submit = () => {
    console.log("Submitting attempt...")
    try {
        router.post(
            props.submit_route,
            {
                answers: answers.value,
                time_taken: timeTaken.value,
            },
            {
                onError: (error) => {
                    console.log("onError", error)
                },
                onSuccess: () => {
                    console.log("onSuccess")
                },
                onFinish: () => {
                    console.log("onFinish")
                },
            },
        )
        console.log("Sent post.")
    } catch (error) {
        console.log("try catch", error)
    }
}
Submitting attempt...
Sent post.
onFinish
POST http://localhost:8000/01972048-29ab-73b3-a09e-2d680cfac87c net::ERR_CONNECTION_REFUSED
Uncaught (in promise) > AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
sudden widget
#

Thing is, Inertia is backend driven, so if the backend/network is down and Inertia site is pretty much unusable. I believe there is an onException callback

tropic osprey
#

There doesn't seem to be onException. In any case I would like to show some error message to the user in case of an internet connection problem so they can try later/ask support. I can't figure out how to do that though 🤔

sudden widget