Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

408
Visualizações
Polymer Iron Ajax - How to access Response from Request after Error Event?

I use iron-ajax:

<iron-ajax
   id="postLoginForm"
   method="POST"
   verbose
   url="../../login"
   content-type="application/json"
   handle-as="json"
   on-response="_handleLoginResponse"
   on-error="_handleErrorResponse"></iron-ajax>

The server always responds with an error if the request body is empty:

Error: The request failed with status code: 422

This triggers my _handleErrorResponse method in which I would like to access the actual response, which looks like this:

{"email":["The email field is required."],"password":["The password field is required."]}

Here is what my _handleErrorResponse looks like:

_handleErrorResponse: function (event) {
  console.log(event);
  console.log(event.detail);
  console.log(event.detail.error);
  console.log(event.detail.error.message);
  console.log(event.detail.request);
  console.log(event.detail.response);
  console.log(event.detail.request.response);
},

And here is what the output looks like:

Developer Tools Output

So, how do I access the response so that I can output it to the view?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I think you can get the error JSON here:

event.detail.request.xhr.response

To get a more complete explanation, you can read the accepted answer to a different, but related question here:

Iron Ajax - How to access Response from on-response function?

Cheers!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda