0

Hi I am doing angularjs application with web api as front end. Whenever some user do not have certain permission I am returning Httpresponsemessage as

var message = string.Format("You do not have permission");
                        HttpError err = new HttpError(message);
                        return Request.CreateResponse(HttpStatusCode.NotFound, err);

I want to alert above message in angular and I am trying as below.

$scope.Update = function () {
        var servCall = ProjectSetting_Service.update(sub);
        servCall.then(function (data) {
            alert(JSON.stringify(data));
            });
    }, function (error) {
//How to alert message here

    }

May I get some help here! Any help would be appreciated. Thank you.

1
  • try console.log('error', error); in your errorCallback function and show the response, you can do this alert(error.data.message); Commented Feb 10, 2017 at 11:28

1 Answer 1

5

Add a view in your html and show that view in the error try this

$scope.showError = false;
$scope.Update = function () {
  var servCall = ProjectSetting_Service.update(sub);
  servCall.then(function (data) {
    alert(JSON.stringify(data));
  });
}, function (error) {
  //alert message  
  $scope.showError = true;    
}

In your html

<div ng-show="!showError ">
    <p> Everything is going fine :)</p>    
</div>
<div ng-show="showError ">
    <p> 404 sorry</p>
</div>
Sign up to request clarification or add additional context in comments.

7 Comments

alert(error.statuscode) something like this can i try to alert 404?
you can but alert in not the best solution, try adding some custom html in place of 404, google.co.in/adsensehfhskdfkjhsdf click on the link and check one example
yes i know but i am just writing server side code and front end is doing someone else. Testing purpouse i want to show 404 in alert.
Yes for testing purpose its fine, Accept my answer if you like it :)
ohh, tell me whats the problem?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.