Search code examples
node.jsexpressvuejs2laravel-5.3axios

204 error code then 500 error code responses


So I have an application which needs to send data to the API which is created by our team leader using NodeJS with Express.js.

On my end I have laravel application which using VueJS for the UI. Inside the Vue JS component. I am using axios to request to the API.

axios.post('https://clearkey-api.mybluemix.net/sendcampaign', request)
                .then(function(response) {
                    //console.log(response);

                })

However, it returns 204 which means according to this https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.

204 No Content

The server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. The response MAY include new or updated metainformation in the form of entity-headers, which if present SHOULD be associated with the requested variant.

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view.

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.

Then next it returns 500 Internal Server Error. So in my opinion it returns this error because there is no content to be returned from the server?

Can you tell me other possible problems why it return that response?


Solution

  • Check if the "HTTP method" of the 204 is OPTIONS and if the method of the 500 is POST.

    If both are like that, then you are seeing first a CORS pre-flight request (the OPTIONS that returns 204) and then the actual request (the POST that returns 500).

    The CORS pre-flight request is a special HTTP message your browser sends to the server when the webpage and the backend are hosted at different addresses. For example, if your website is hosted at http://localhost but the backend you are trying to access is hosted at https://clearkey-api.mybluemix.net.

    The reason of the 204 just means your backend endpoint is correctly setup to handle requests for /sendcampaign (you can ignore it). The reason of the 500 is because of some exception in the implementation of the function that handles that endpoint.