Answer the question
In order to leave comments, you need to log in
How to properly organize error handling logic?
Hello.
There is a SPA on vue.js.
There is a wrapper for API calls. For some error codes, the reaction should always be unambiguous (just displaying a message with the error text), for other codes there should be an individual reaction depending on ...
I want the error message to show the wrapper, and if the error requires individual processing, then not would do nothing.
All communication with the API is based on promises.
Elementary example:
this.$apiImpl.users.index()
.then(response => {
//....
})
.catch(error => {
//....
})
.finally(() => {
//....
})
axios.get(...)
.catch(error => {
if (!...) return Promise.reject(error); // если ошибка обрабатывается индивидуально
// делаем все, что нужно (показываем сообщение)
return Promise.reject('error_handled')
})
if ('error_handled' === error) return;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question