Angular $http error response statusText always undefined

后端 未结 3 993
我寻月下人不归
我寻月下人不归 2020-12-19 19:20

I am trying to return a custom error message to the user to let them know what went wrong if an error occurs, but I have tried everything to display the message and nothing

3条回答
  •  生来不讨喜
    2020-12-19 19:46

    Replace .error() by .catch().

    $http.post('/url',json)
        .success(function(data, status, headers, config){
    
          // some code here
    
        })
        .catch(function(data, status, headers, config){ // <--- catch instead error
    
            data.statusText; //contains the error message
    
        });
    

提交回复
热议问题