Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

handle-callback-err Expected error to be handled

I have eslint enabled in my vue webapp, I have 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 I want to do, still I get following error from the liner:

✘ http://eslint.org/docs/rules/handle-callback-err Expected error to be handled ~/vue/src/store/modules/myStore.js:97:9 error => {

I can add following comment to convert this into warning:

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

But how do I suppress this completely or modify code, so that this error doesn't come.

like image 803
Saurabh Avatar asked Nov 25 '16 08:11

Saurabh


2 Answers

Just had the same thing, and the warning message is misleading; it's actually because error is not referenced in the code, not because it's not "handled".

Make sure you do something with error, such as a console.log() or don't include it as an argument:

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

// don't define argument:
() => {
  console.log('Inside error, fetching product line items failed')
  router.push({path: '/'})
}
like image 174
Dave Stewart Avatar answered Sep 21 '22 18:09

Dave Stewart


try this:

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

if there is an error, you need to handle it in your code.

like image 32
NicoS Avatar answered Sep 18 '22 18:09

NicoS