3👍
✅
I think part of your problem is that you’re mixing async/await style of writing code with promise-chaining style. When you return ‘fail’ or ‘success’, you’re usually returning from the axios.get
callback, not from the getSomething
method. You might want to rewrite your code a little like this:
async getSomething () {
console.log('getSomething')
if (condition) {
try {
let response = await axios.get('api_url')
console.log('getSomething success')
return 'success'
}
catch(error) {
console.log('getSomething fail 1')
return 'fail'
}
} else {
console.log('getSomething fail 2')
return 'fail'
}
}
Source:stackexchange.com