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

205
Visualizações
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 Respostas
Responde à pergunta

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 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