我想处理错误服务,现在我想手动将单个错误放入服务中,我想自动进行处理

时间:2019-02-02 04:21:08

标签: javascript angularjs

我想处理错误服务,现在我想手动将单个错误放入服务中,我想自动进行处理。

'use strict';
angular.module('nexoolApp.errorservice', ['nexoolApp.config'])
  .service('Errorservices',['nexoolConfig', function (nexoolConfig) {
    //console.log('Inside Errorservices');
    var showmessage=nexoolConfig.defaultErrorMessage;
    this.geterrordetails = function(data)
    {
        if(data.errors) {
            if (data.errors.USER_NOT_PROVIDED) {
                showmessage = data.errors.USER_NOT_PROVIDED.message;
            } else if (data.errors.ADMIN_NOT_PROVIDED) {
                showmessage = data.errors.ADMIN_NOT_PROVIDED.message;
            }
}
        return showmessage;
    };

}]);

1 个答案:

答案 0 :(得分:2)

假设您已经描述了这种情况:

'use strict';
angular.module('nexoolApp.errorservice', ['nexoolApp.config'])
  .service('Errorservices',['nexoolConfig', function (nexoolConfig) {
    //console.log('Inside Errorservices');
    var showmessage=nexoolConfig.defaultErrorMessage;
    this.geterrordetails = function(data)
    {
        if(data.errors) {
            for ( var property in data.errors ) {
                showmessage = data.errors[property]['message'];
                break;
            }
        }
        return showmessage;
    };

}]);