I'm calling a private REST API with axios as http-client. If I'm calling an endpoint which should respond some information about an object I get an response (status code 200, payload containing the info, and so on). If I'm requesting an object which does not exist the REST API responds with status code 204 and no payload. Which is fine in my opinion BUT my problem is that axios doesn't react on this response.
HERE IS WHAT I HAVE:
This function is used to dynamically call endpoints with the provided endpoint request method and endpoint URI (This is some project specific stuff).
restApiService.triggerEndpoint(endpointReqMeth, endpointUri, inputData)
.then(response => {
// handling successfull response here
})
.catch(err => {
// handling error response here
})
The triggerEndpoint function calls the required axios method depending on the request method of the endpoint:
triggerEndpoint = function (edPoURI, edPoReqMethod, params) {
switch (edPoReqMethod) {
case 'GET':
return axios.get(edPoURI, {
params: {
...params,
},
});
case 'POST':
return axios.post(edPoURI, {
...params,
});
}
};
WHAT I WANT:
If I receive a status code 204 I'd expect that I end up in the then-block of the restApiService.triggerEndpoint function to handle the response regarding to its status.
WHAT IS HAPPING:
After calling the function triggerEndpoint (in this specific case the axios.get function) the request is forwarded to the REST API which does its magic and responds with status code 204 and no payload. But in my backend...nothing happens.
The backend process doesn't react in any way.
Here is a screenshot of a soapui request of the same endpoint with the same data showing that the REST responds with 204 if a not existing object (in this case 123) is requested
Can you help me out? What am I missing here? How should axios behave in this case?
I guess axios receives the response but something happens that its not been handled. I'm guessing this because if axios wouldn't get a response the timeout should kick in sometime which never happens.
Thanks a lot in advance