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

204
Vistas
Perform action on different server responses

On the moment, I am at the point where the client can send requests to the server, have the server perform actions and send back a response to the client.

For exemple, when I want to change a password, I verify the old password in my database. If it matches, the password is updated and I send a 200 response like so :

sendResponse("User's Password Updated", exchange, 200, true);
which is read in chrome's network tab as : { "response" : "User's Password Updated"}

If the old password is wrong (can't verify the user's identity), it sends the following message : sendResponse("User's password could not be verified", exchange, 200, true);
which is read in chrome's network tab as : { "response" : "User's password could not be verified"}

Now what I want to do is to perform a different action on my client for each action. For this exemple, let's log a message.

I want to have something like that (pseudocode):

if (response === "User's password could not be verified")
   console.log('User's password could not be verified');
else if ( response === "User's Password Updated")
   console.log('User's Password Updated');

keep in mind this is my first time using http, and I am pretty happy with myself being able to display the different responses in the network tab

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

0

As I said in my comment you should conditionally display a message based on the http response code, not message.

To do that you would modify your code to this:

sendResponse("User's password could not be verified", exchange, 401, true);

Then in your if statement you would do:

if (response.status === 401) {
   console.log('User's password could not be verified');
} else if ( response === 200) {
   console.log('User's Password Updated');
}

I suggest you read up on the response object: Response and HTTP Status Codes..

This also may help.

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