I'm trying to simplify handling of HTTP Status Codes for a REST API.
I would like to know which of the following intervals of status codes have the possibility to occur in REST API?
-Informational responses (100–199)
-Successful responses (200–299)
-Redirects (300–399)
-Client errors (400–499)
-Server errors (500–599)
It is currently handling only 3 intervals of HTTP Status Codes in the following way.
Is it necessary to handle the remaining 2 intervals namely Informational responses (100–199) and Redirects (300–399)?
I'm really confused and trying to find the correct solution to handle http status codes on both server side and client side.
SERVER SIDE
switch(Math.floor(statusCode/100)){
case 2:
err.status = 'OK'
break;
case 4:
err.status = 'CLIENT ERROR';
break;
case 5:
err.status = 'SERVER ERROR';
}
res.status(statusCode).json({
status: status,
message: message
data: data
});
CLIENT SIDE
const res = axios.get('https://www.example.com/things);
if(res.data.status == 'OK'){
showThings(res.data.data);
console.log('Request successfully processed.');
} else if(res.data.status == 'CLIENT ERROR') {
console.log('Request failed due to client error');
} else if(res.data.status == 'SERVER ERROR') {
console.log('Request failed due to server error.');
}