Get $http response error status on AngularJS
<p>I follow an online course in AngularJS and I am on the first steps of learning it.</p>

<p>I am trying to call an API after a form submission and based on the API response, show and hide some data.</p>

<p>What I try to do first is to check the status response in case it returns 500 error for invalid API call. However, it seems I cannot do it.</p>

<p>Part of my service file:</p>

<pre><code>  service.getMenuItem = function (shortName) {

    return $http.get(ApiPath + '/menu_items/' + shortName + '.json')
    .then(function successCallback(response) {
      return response.data;
    }, function errorCallback(response) {
      return response.status;
    })
  };
</code></pre>

<p>And on my controller:</p>

<pre><code>SignupController.$inject = ['MenuService'];
function SignupController(MenuService) {
  var signupCtrl = this;

  signupCtrl.submit = function () {
    signupCtrl.response = MenuService.getMenuItem(signupCtrl.user.favouritedish);
    if ( signupCtrl.response == 500 ) {
      signupCtrl.dishError = true;
    }
  };
}
</code></pre>

<p>If I don't have any error on the $http call, everything work as it should. However, with the 500 error, it seems that it doesn't. I tried to log the <code>signupCtrl.response</code> on my controller and the <code>value: 500</code> is there. But the if cannot be validated.</p>

<p>Version 1.5.8 on AngularJS</p>