If(err) throw err VS .catch(err => console.log(err)

I’m confused as to why errors are handled in two different ways when using bcrypt.

.catch(err => console.log(err))

Basically, never do this. It captures and ignores all errors after logging them. The default behavior for an uncaught error is to print it anyway (with console.error) and it won’t cause weird behavior in the rest of your program by continuing on with invalid data.

As for bcrypt returning an error instead of throwing it, that’s pretty nonstandard behavior. Crypto libraries often do weird things for attack mitigation though.

1 Like