Fetch Request If Not Receiving A Status Code of Somewhere in the 2xx Range Auto console.errors, Why?
Unanswered
Eurasian Collared-Dove posted this in #help-forum
Eurasian Collared-DoveOP
Hey, I'm working on an application in Next and currently just have a very simple login system using mongodb as the store. There is a register route and a login route, the register is just some basic stuff to get input, connect to the db, and post a request to create a new user with the username and bcrypt hashed password, and the login route is basically the same, just finds a user and compares the password rather than creating one. On the server side there can be errors that happen in terms of the username not being unique, if that is the case I have a try catch block that wraps the attempt to create a user so if there is an error the app doesn't crash, on catching of an error it has some paring to check some basic things and see if the error is a
duplicate key error or just another error, if it is, it parses the message in a specific way. All of this is to say after receiving the error, a response is generated with the body of the parsed error and some base information to display the error info to the user on the front end. This is all fine and dandy, and works no matter the status code, as long as it is within the range of 100-600, the request/fetch sends and receives fine, however if the number is outside the range of 200-299 the fetch gets immediately logged. Is there any way to change this behavior to be able to pass back a code of like 401 without the fetch being logged out immediately?