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, 14) === 'Not authorized')

Firstly why the back-end sends either a string or an object.
Secondly ‘Not authorized’ has only 13 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.

Leave a Reply

Your email address will not be published.

%d bloggers like this: