Tuesday, 30 May 2017

ESLint: return and throw in the same function

I have code like this

function errorHandler (error) {
    // crashes and burns
    if(error.type === Error.TRANSPORT_ERROR){
         throw error;
    }
    // accept the error and move on
    return handleApplicationError(error)
}

and works as okay but then eslint complains about this code saying

Expected to return a value at the end of function 'errorHandler' consistent-return

which means it is expecting me to include a return statement in the if block which kinda sucks because i already have a throw statement there (which as i discovered sorta work like return (but an evil twin)).

How can i make eslint happy without turning off the rule?

Anyone?



via shanks

No comments:

Post a Comment