Alex Ghiu
Alex Ghiu

Reputation: 86

Polymer iron-form or iron-ajax error response content

I'm using Polymer 1.0 with Golang 1.5.

From Go I'm sending a json response with a 400 Bad Request and some content as follows:

d := struct{
    Message string
}{
    Message: "details should go in here"
}
j, _ := json.Marshal(d)
w.WriteHeader(http.StatusBadRequest)
w.Write(j)

In polymer I've tried to get the contents of this error both with iron-form and iron-ajax and I keep on getting the following in e.detail:

"Error: The request failed with status code: 400 at iron-request."

Here is my Polymer code:

<form is="iron-form" method="post" action="golang-handler-above">
    <paper-button on-tap="_submitHandler">Send</paper-button>
</form>

Polymer({
    ...
    listeners: {
        "iron-form-error": "_ironFormErrorHandler",
    },

    _ironFormErrorHandler: function(e) {
         console.log(e.detail)
    },
    ....
})

Now I'm looking for some way of accessing the contents of the response. Some property of e that will allow me to access the "Message" field that is being returned with the response, or even the raw response body as text.

Upvotes: 2

Views: 835

Answers (1)

Devappended
Devappended

Reputation: 104

Try this...

_ironFormErrorHandler: function(e, detail) {
    console.log(detail)
},

Upvotes: 0

Related Questions