DEV Community

loading...

Overchecking errors [#3 Scary Code]

Bogdan Alexandru Militaru
Get whatever you want from me [here](https://boobo94.github.io/)
Originally published at boobo94.xyz on ・1 min read

When I started programming I had a problem trying to overcheck everything, all the errors, and everything. These days I discovered something similar:

(typeof err === 'object' && err.status==403) ||
(typeof err === 'string' && err.substring(0, 15) === 'Not authorized')

Firstly why the back-end sends either a string or an object.
Secondly 'Not authorized' has only 14 characters, which means the second condition still fails if we suppose that the error thrown by the server starts with Not authorized.

Remember, this is a series with scary code, so if you wanna see the complete list, you can do it here.

The post Overchecking errors [#3 Scary Code] appeared first on boobo94.

Discussion (0)