It talks to our API routes, also written in JS. The UI is based on Bootstrap + commercial UI template. We used React/Redux architecture for web front end.
We have a button that uploads a file the user has selected, by calling our our API. We noticed that often our API returns status 200 or status 201 for successful requests. Is there a reason the status is randomly 200 or 201?
We used to check for success by checking for:
if (res.status === 200)
What is the best practice? Is there a clever way to check for all types of success status? Or should we always hard code:
if (res.status === 200 || res.status === 201)
Is there a way to avoid code duplication?