Handle-callback-err Expected error to handle

I have eslintincluded in my vue webapp, I have the following code:

myApi.get('products/12').then((prodResponse) => {
  state.commit('ADD_PRODUCT', {product: prodResponse.data})
},
error => {
  console.log('Inside error, fetching product line items failed')
  router.push({path: '/'})
})

This is the error handling that I want to do, but I get the following error from the liner:

http://eslint.org/docs/rules/handle-callback-err Expected error to handle ~ / Vya / SRC / store / modules / myStore.js: 97: 9 error => {

I can add the following comment to convert this to a warning:

/* eslint handle-callback-err: "warn" */

But how can I suppress this completely or change the code so that this error does not occur.

+4
source share
2 answers

try the following:

error => {
  console.log('Inside error, fetching product line items failed', error)
  router.push({path: '/'})
}

, .

+1

, , :

if , :

error => {
  if (error) {
    console.log('Inside error, fetching product line items failed')
    router.push({path: '/'})
  }
}

, , :

/* eslint handle-callback-err: "warn" */

.

0

Source: https://habr.com/ru/post/1661917/


All Articles