0
votes

I have a method to call a login endpoint on a button click

login() {
                let email = this.user.email
                let password = this.user.password
                axios.post('invalidRoute').then( (response) =>{
                    console.log('success')
                    console.log(response.data)
                }).catch(function (error) {
                    console.log('error')
                    console.log(error)
                })
            },

No matter what I set as the url route, axios thinks that the post is successful and always logs out the success message and a blank response data.

I import axios directly at the top of the component using the line

import axios from 'axios'

I don't use it anyhere else.

This is in a basic nativescript vue js application.

this is what my main.js looks like

import Vue from "nativescript-vue";
import Vuex from 'vuex'
import store from './store/store';
import * as applicationSettings from 'tns-core-modules/application-settings'

import router from './router'

Vue.prototype.$router = router


Vue.config.silent = false
Vue.use(Vuex)

new Vue({
    render: h => h('frame', [h(router['login'])]),  store

}).$start()

It is driving me nuts, I cant see why it won't trigger the catch.

2

2 Answers

0
votes

I think it's an issue with Axios. With {N} status code will be null when request fails, seems Axios considers that request as success when the status code has falsy value.

Looks like there is a similar issue logged in their Github.

0
votes

I found that axios nor http doesn't call anything in some circumstances. I don't know why, i was investigated this for two days. No clue. Just used Fetch instead and for now everything works fine.