Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
How to throw Catch in fetch POST request in react native

I am having a problem with calling an error when i call a POST request in React Native, i know that there is a catch but it only throws for network connections, how do i do that with errors i get from the response when i have a wrong password or wrong username like when this Error is called from the Response:

Object {
  "error": "invalid_request",
  "error_description": "Missing form parameter: grant_type",
}
    fetch("https://websiteo.com/auth/realms/realmsid/protocol/openid-connect/token", {
      method: 'POST',
      headers: myHeaders,
      body: urlencoded.toString(),
    })
      .then(response => response.json())
      .then(result => {
        //console.log(result)
        console.log(result)
        saveToken('secure_access_token', `${result.access_token}`)
        props.navigation.navigate('HomeApp') //i need to throw catch also when username or password wrong
      })
      .catch(error => alert(error.response.data)) //This is only thrown when network problems 

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can verify in response json if was 200 or failed, something like this:

fetch("https://websiteo.com/auth/realms/realmsid/protocol/openid-connect/token", {
  method: 'POST',
  headers: myHeaders,
  body: urlencoded.toString(),
})
  .then(response => {
     if (response.ok) {
        return response.json();
     } else {
        throw new Error('Something went wrong');
     }
  })
  .then(result => {
    //console.log(result)
    console.log(result)
    saveToken('secure_access_token', `${result.access_token}`)
    props.navigation.navigate('HomeApp')
  })
  .catch(error => alert(error.response.data)) //This is only thrown when network problems 
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda