DEV Community

Bogdan Alexandru Militaru
Bogdan Alexandru Militaru

Posted on • Originally published at boobo94.xyz on

Overchecking errors [#3 Scary Code]

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.

Latest comments (0)