Ajax $http错误函数未显示错误消息

Ajax $http错误函数未显示错误消息,ajax,angularjs,spring-mvc,exception-handling,Ajax,Angularjs,Spring Mvc,Exception Handling,当ajax调用失败时,我必须给用户一个正确的消息 我的Ajax调用如下所示: $http({ method:'PUT', url:"/myapp/web/update", crossDomain:true, data:dataobj, headers:{ 'Conten

当ajax调用失败时,我必须给用户一个正确的消息

我的Ajax调用如下所示:

$http({
                method:'PUT',
                url:"/myapp/web/update",
                crossDomain:true,               
                data:dataobj,
                headers:{
                    'Content-Type':'application/json',
                }
            }).success(function (data) {                
                console.log("error"+JSON.stringify(data));
            }).error(function (data, status, headers, config) {
                console.log("error"+JSON.stringify(data));
            });
从背面来看,我使用SpringMVC4作为restfull api。因此,我正在验证数据并相应地发送响应。如果验证出错,我抛出自定义异常

现在,如果我抛出just exception,它被缓存在Ajax成功函数中,但我希望它必须在error函数中捕捉到这一点。为此,我添加了以下代码行:

  response.sendError(500);
现在它像预期的那样被缓存在错误函数中,但我找不到带有它的JSON错误消息。有人能告诉我代码哪里出错了吗

编辑:

下面是我用错误消息响应的代码

@ControllerAdvice
public class ExceptionHandlingController{

@ExceptionHandler(EmployeeNotFoundException.class)
public @ResponseBody ExceptionJSONInfo handleEmployeeNotFoundException(HttpServletRequest request, Exception ex){

    ExceptionJSONInfo response = new ExceptionJSONInfo();
    response.setUrl(request.getRequestURL().toString());
    response.setMessage(ex.getMessage());
    response.sendError(500);
    return response;
    }
}

发布一些api代码method@AjinderSingh我已经添加了代码。您使用的是angular的哪个版本?@NikolayRusev AngularJS v1.3.17您是否定义了自定义http拦截器?如果有的话。请将代码添加到您的问题中