Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All POST requests being sent twice. #25

Closed
geefinator opened this issue Mar 15, 2015 · 5 comments
Closed

All POST requests being sent twice. #25

geefinator opened this issue Mar 15, 2015 · 5 comments

Comments

@geefinator
Copy link

As far as I can tell in version 0.5.3, all of my POST requests are being sent twice. Once with the proper data I would expect (though this seems to happen silently as it is not picked up by the dev tools in browser, but it is in my api server's logs.), then a second time with the payload of nothing for all data variables. So basically, every time I post, I am seeing two separate POST requests to the api server. One that is legitimate and one that is just a garbage request with no data payload.

developer_tools_-http___localhost_9000_

an example request with empty payload

carriage_ root_carriage-api___var_www_carriage_current ssh 150x44_and_developer_tools-http___localhost_9000_

Excerpt from the api server logs showing two posts back to back, one with the data, one without.

My code is fairly straight forward:

  addOrganization(){

    var json = {
      'name': this.org_name,
    };
    return this.http.post(this.new_org_url, json).then(response => {
      var dataobj = JSON.parse(response['response']);
      if (response['statusCode'] == 201){
        console.log('Success');
      }else{
        alert("something went wrong");
      }
    });
@geefinator
Copy link
Author

Just to update, as you will notice I was allowing the bad requests to save as objects on the api. I went ahead an threw a 400 if the data was empty, and sure enough as I expected, the http-client ignored the 400 and came back with the 201 (of the good request with the proper data).

@zewa666
Copy link
Member

zewa666 commented Mar 16, 2015

Hi there,

I've created a Unit Test to check whether it's an API issue. Seems not to be so. Here is the code if you wan't to check it yourself:

      it('should make only one request (Issue #25)', () => {
        var content = { name: "A demo name" };
        var client = new HttpClient()
          .configure(x => {
            x.withBaseUrl(baseUrl);
            x.withHeader('Content-Type', 'application/json');
          });

        client.post('some/cool/path', content);
        expect(jasmine.Ajax.requests.count()).toBe(1);
      });

So I guess it's related to something specific to your application. Dunno maybe you're calling the method by incident a second time or so. Just add a breakpoint to your addOrganization() method to see if it's executed twice.

@geefinator
Copy link
Author

The addOrganization() function is only being called upon a form submittal. So unless the form is being submitted twice, I am not sure how my application would be making double requests. Just the behavior of the two requests really seems like a bug somewhere. One was completely silent as far as dev tools was concerned, the other was not. I will take a look again at my code, but it really is dead simple whats going on.

@geefinator
Copy link
Author

And now it seems to no longer be doing it at all. shrug. I did do some refactoring of all that code so i suppose I must of been doing something whacky previously. Thanks for taking the time to write up a test case for my own error :)

@zewa666
Copy link
Member

zewa666 commented Mar 16, 2015

No problem at all. Glad it got solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants