0

My code was working fine until today, so basically what this API does is it sends a default gcm-id to server and logs out the user, but I keep receiving this error from this morning, and I don't know if it's related to server-side or client, so here's my code and I wonder if I'm doing something wrong or what can I do to fix it?

const ExitAccount = () => {
      const user = {
            gcm_id: 1
      };
      const options = {
            headers: {
                 'Authorization': this.state.Authorization,
                 'content-type': 'application/json'
                 }
            };
            axios.post('sth', { gcm_id: 1 }, options)
                .then((response) => {
                    this.setState({ loading: false, Authorization: "sorryBuddy", profile: 
                    "dropdownProfile hidden", login: "dropdownLogin show" })
                    localStorage.setItem('api_key', this.state.Authorization);
                    console.log(response)
            });
}

And when I open network to see what's the problem it returns this

message: "can't find gcm_id"
AmerllicA
  • 29,059
  • 15
  • 130
  • 154
the preacher
  • 285
  • 3
  • 7
  • 23
  • The code at first glance looks acceptable. You did not include any information about your server code, so it's hard to tell. You also did not include your axios configuration. – Aoi Karasu Apr 01 '20 at 09:28

2 Answers2

0

The second parameter of the post request is { gcm_id: 1 }. I see that you've also declared the user above, but you are not using it at all. It's probably an inconsistency between what you send as parameters from the client and what the backend server expects to find in parameters.

I would look there first.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
0

You may want to try:

axios.post('sth', {data: {gcm_id: 1}, options)

or adding the data in your header such as:

const options = {
        headers: {
             'Authorization': this.state.Authorization,
             'content-type': 'application/json'
             },
        data: {gcm_id: 1}
        };

Hope this helps

DcoderZ
  • 120
  • 1
  • 9