PolymerElements / iron-ajax

Easily make ajax requests
https://www.webcomponents.org/element/PolymerElements/iron-ajax
127 stars 113 forks source link

e.detail.request.response is set to null if server returns an error (e.g. 422). e.detail.request.xhr.response is filled #220

Closed mercmobily closed 8 years ago

mercmobily commented 8 years ago

Description

Having a form like this:

    <form is="iron-form" on-iron-form-response="_response" on-iron-form-error="_error" id="form" method="post" action="/stores/polymer">
       <paper-input required id="surname" name="surname" label="Your surname"></paper-input>
 </form>

And then defining the handlers:

      _response: function( e ){
        console.log("Response received, OK!")
        console.log( e.detail );
      },
      _error: function( e ){
        console.log("Response received, ERROR!")
        console.log( e );
        debugger;
      }

And making sure that the server returns error 422...

Expected outcome

In _error, I expect e.detail.request.response to be set as the data returned by the object.

Actual outcome

e.detail.request.response is null; to get the response, I have to ask `e.detail.request.xhr.response which feels a little hacky, since the request is in fact done and e.detail.request.response should be set.

Sorry, no live demo as it requires a server returning an error...

mercmobily commented 8 years ago

Just got bitten by this once again while writing unit tests for the same element! (This time using sinon...)

mercmobily commented 8 years ago

I am amazed nobody had noticed till now...?

mercmobily commented 8 years ago

(Thanks for fixing it!)