2

I have a nativescript vue.js application that is hitting an endpoint to get a token when the user clicks login using axios.

when the emulator phone is offline the axios call is still made and the then is executed as if there was a successful request made, looking at the network tab there is a request made but it is pending forever and the axios call returns immediately.

if I run axios in a browser based application it does not seem to fail in the same way.

This is my calling code for:

   methods:{
            submit()
                { this.axios.post('https://backendauth.free.beeceptor.com/api/login',this.user)
                .then((response) => {
                    console.log('Detected as a success')
                    console.log(response.status)
                    console.log(response)
                    console.log(response.data.success.token)
                    this.data = JSON.stringify(response.data)
                    this.$navigateTo(this.$router['home'])
                }).catch((err)=>{
                    if (err.response.status === 401) {
                        console.log(err)
                    }
                    else
                    {
                        console.log(err.response)
                    }

                    })
                this.submitting = 'form clicked'
            }

I have created a repo that demonstrates this

https://github.com/jachno/basicAuth

This image shows the console request being successful with the device online

Working Request

and this shows the call working over the network

Network call

And this shows the network pending request when it is in flight mode

enter image description here

This now shows what the console looks like when the device in in flight mode:

Console with Flight mode enabled

1 Answer 1

4

When the Http call fails, the status is set to null, Axios considers that as a success. So the workaround could be verifying whether your status is null, on your success callback. If it's null, then consider it as failure.

You may also check whether connectivity is set to none, to find out whether your device is really offline.

You might want to raise a bug in the Github repo regarding this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.