Kelevra_V
Handling status codes using $fetch and try/catch statements
TL;DR: how do you handle http status codes using $fetch.
Apologies if this is a newbie question but I'm curious what the best practice is for the following scenario. The nuxt client calls the nuxt server, the nuxt server calls the separate backend. As an example, for a login, if the backend returns a 400, that means a 2FA code is required. The way I have it set up now is that the call from nuxt client to nuxt server returns a 200 with the backend response, and I read that response to determine how to handle it. I was told this is inconsistent; the nuxt server should also return a 400 and should handle that. Since a 400 is considered an exception, my code would need to look something like this:
Hoping for some feedback or discussion on whether this is the proper approach. Thanks in advance.
3 replies