Dr. Abbos
Dr. Abbos

Reputation: 139

Difference between response.statusCode and response.status

I was writing a function that shows dialogwindow on the button click:here the piece of code related to status and statusCode.

     if(response.status>300){
                  jQuery("#myModal").modal("show");
                }else{
    vm.someFunction();
                }


  // when I run the code above I got result working, however when I wrote //the following:



  if(response.statusCode>300){
                   jQuery("#myModal").modal("show");
                }else{
    vm.someFunction();
                }

// it does not work although my statusCode was 500;

So, my question is: what is the difference between status and statusCode and when I should use some of them.?

Upvotes: 4

Views: 6147

Answers (1)

robertklep
robertklep

Reputation: 203519

Client-side (in the browser), and using XMLHttpRequest or fetch, the correct property to use is called response.status

Server-side, in Node.js, using http.ClientRequest (when dealing with the response of an HTTP request that you made using Node.js), the correct property to use is called response.statusCode

Also server-side, in Node.js, using http.ServerResponse (to set a status code for a particular response), the correct property to use is also called response.statusCode

Upvotes: 7

Related Questions