It is as follows
I'm new to javascript and I'm not sure how to handle this error. I'm trying to call a function and putting a .catch()
to avoid the error UnhandledPromiseRejectionWarning shortly after it, but I would like to check 'in case an error occurs, .
I tried to do this check using a if()
, but my console for SyntaxError: unexpected token if . I have tried to use try...catch
, but the error occurred UnhandledPromiseRejectionWarning I said ... My code looks like this:
//um pouco de código aqui
function(args).catch(error => console.log(error),
if(error){
//Código que deve ser executado caso ocorra erro
});
//um pouco mais de código aqui
In short, is it possible to put if()
within .catch()
? Is there a better way to do this?