0

In my application all server responses are as follows:

response = {
    data: {},
    status: STATUS_CODE,
    message: STRING_MESSAGE
}

I want to use angular's http response function to display a response message for some of my webservices in a toast component. In the interceptor I have a simple response function:

response = function (res) {
    console.log(res);
    return res;
}

which logs a response object:

{
    data:{}, // object response.data
    config: {},
    status: 200,
    statusText: 'OK',
    headers: function()
}

There is no message parameter that server sends. Does it mean that interceptor erase some part of my servers response? One of the solutions would be to overwrite a statusText value. I tried to modify server response like

response = {
        data: {},
        status: STATUS_CODE,
        statusText: STRING_MESSAGE
    }

but it didn't work, I still had statusText: 'OK' and still no message param in interceptor's response object

3
  • the server response is in data property. That should not be empty object or something is wrong in actual request Commented Sep 28, 2016 at 15:02
  • The interceptor's response.data is not empty and is the same as server's response.data, so has no status and no message attribute. Commented Sep 28, 2016 at 15:05
  • then inspect the actual request in dev tools network and see exactly what is sent. Also a demo in plunker showing this would help. perhaps you forgot to return something in the interceptor? not enough context shown and it's a bit confusing as shown Commented Sep 28, 2016 at 15:06

1 Answer 1

0

Check data property in your interceptor response. It might be like this

{
   data:{     
      data: {},
      status: STATUS_CODE,
      message: STRING_MESSAGE
   }, // object response.data
   config: {},
   status: 200,
   statusText: 'OK',
   headers: function()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.