diff --git a/src/server/index_patterns/service/lib/errors.js b/src/server/index_patterns/service/lib/errors.js index a2ef9f1cc396d..61158e9e67f8b 100644 --- a/src/server/index_patterns/service/lib/errors.js +++ b/src/server/index_patterns/service/lib/errors.js @@ -47,6 +47,10 @@ export function convertEsError(indices, error) { return createNoMatchingIndicesError(indices); } + if (error.isBoom) { + return error; + } + const statusCode = error.statusCode; const message = error.body ? error.body.error : undefined; return Boom.wrap(error, statusCode, message); diff --git a/test/api_integration/apis/index_patterns/es_errors/errors.js b/test/api_integration/apis/index_patterns/es_errors/errors.js index ed4b0716f23a2..8bf3350590d07 100644 --- a/test/api_integration/apis/index_patterns/es_errors/errors.js +++ b/test/api_integration/apis/index_patterns/es_errors/errors.js @@ -1,5 +1,6 @@ import expect from 'expect.js'; import { errors as esErrors } from 'elasticsearch'; +import Boom from 'boom'; import { isEsIndexNotFoundError, @@ -106,6 +107,16 @@ export default function ({ getService }) { expect(converted).to.have.property('isBoom'); expect(converted.output.statusCode).to.be(403); }); + + it('handles errors that are already Boom errors', () => { + const error = new Error(); + error.statusCode = 401; + const boomError = Boom.wrap(error, error.statusCode); + + const converted = convertEsError(indices, boomError); + + expect(converted.output.statusCode).to.be(401); + }); }); }); }