2

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 requestedenter image description here

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

db3000
  • 400
  • 5
  • 16
  • Well, I think you should take a look in their repo and create an issue to get a better help – Giovane Jan 14 '21 at 13:55
  • 1
    I hope this link will help you: [similar](https://stackoverflow.com/questions/63866468/axios-post-request-returns-204-no-content-status-what-do-i-need-to-change-to-ge) – olgunyldz Jan 14 '21 at 14:01
  • But in my backend...nothing happens., what do you mean by that?, are you talking about triggerEndpoint's then method? – Sudhanshu Kumar Jan 14 '21 at 14:09
  • 1
    @Ashu its just stuck. I call the axios.get method and after that "nothing" happens. I neither enter the then- or catch-block. I get no response at all from the axios.get function and so my backend "does nothing" from that point on. – db3000 Jan 14 '21 at 14:13
  • 1
    I would ask you add debugger breakpoints and track function step and step and see where it leads to, this is the only way to solve it, if it ends up dying in the axios itself and then probably you should file an issue, or there might be something else ( i suspect the chances of latter the most ) – Sudhanshu Kumar Jan 14 '21 at 14:56

0 Answers0