allow notifier.error to handle angular $http object

Fixes #5825
This commit is contained in:
Timothy Sullivan 2016-01-05 16:54:14 -07:00 committed by Tim Sullivan
parent bea91c9dbd
commit cac7054ae7
2 changed files with 21 additions and 0 deletions

View file

@ -21,6 +21,22 @@ describe('formatMsg', function () {
expect(actual).to.equal('error message'); expect(actual).to.equal('error message');
}); });
it('should handle a simple Angular $http error object', function () {
var err = {
data: {
statusCode: 403,
error: 'Forbidden',
message: '[security_exception] action [indices:data/read/mget] is unauthorized for user [user]'
},
status: 403,
config: {},
statusText: 'Forbidden'
};
var actual = formatMsg(err);
expect(actual).to.equal('Error 403 Forbidden: [security_exception] action [indices:data/read/mget] is unauthorized for user [user]');
});
it('should handle an extended elasticsearch error', function () { it('should handle an extended elasticsearch error', function () {
var err = { var err = {
resp : { resp : {

View file

@ -1,4 +1,6 @@
define(function (require) { define(function (require) {
var _ = require('lodash');
var has = _.has;
var formatESMsg = require('ui/notify/lib/_format_es_msg'); var formatESMsg = require('ui/notify/lib/_format_es_msg');
/** /**
@ -22,6 +24,9 @@ define(function (require) {
rtn += esMsg; rtn += esMsg;
} else if (err instanceof Error) { } else if (err instanceof Error) {
rtn += formatMsg.describeError(err); rtn += formatMsg.describeError(err);
} else if (has(err, 'status') && has(err, 'data')) {
// is an Angular $http "error object"
rtn += 'Error ' + err.status + ' ' + err.statusText + ': ' + err.data.message;
} }
return rtn; return rtn;