diff --git a/src/ui/public/notify/__tests__/lib/_format_msg.js b/src/ui/public/notify/__tests__/lib/_format_msg.js index 52d9546216db..8961509db5ac 100644 --- a/src/ui/public/notify/__tests__/lib/_format_msg.js +++ b/src/ui/public/notify/__tests__/lib/_format_msg.js @@ -21,6 +21,22 @@ describe('formatMsg', function () { 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 () { var err = { resp : { diff --git a/src/ui/public/notify/lib/_format_msg.js b/src/ui/public/notify/lib/_format_msg.js index e0458816836d..2331d01a7659 100644 --- a/src/ui/public/notify/lib/_format_msg.js +++ b/src/ui/public/notify/lib/_format_msg.js @@ -1,4 +1,6 @@ define(function (require) { + var _ = require('lodash'); + var has = _.has; var formatESMsg = require('ui/notify/lib/_format_es_msg'); /** @@ -22,6 +24,9 @@ define(function (require) { rtn += esMsg; } else if (err instanceof Error) { 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;