diff --git a/src/server/index_patterns/service/lib/errors.js b/src/server/index_patterns/service/lib/errors.js index 490af62bfa8bf..26d2759f0d24c 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.boomify(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 fdabf5bea6910..46b7ab75d41fc 100644 --- a/test/api_integration/apis/index_patterns/es_errors/errors.js +++ b/test/api_integration/apis/index_patterns/es_errors/errors.js @@ -117,6 +117,17 @@ export default function ({ getService }) { expect(converted.output.statusCode).to.be(401); }); + + it('preserves headers from Boom errors', () => { + const error = new Error(); + error.statusCode = 401; + const boomError = Boom.boomify(error, { statusCode: error.statusCode }); + const wwwAuthenticate = 'Basic realm="Authorization Required"'; + boomError.output.headers['WWW-Authenticate'] = wwwAuthenticate; + const converted = convertEsError(indices, boomError); + + expect(converted.output.headers['WWW-Authenticate']).to.be(wwwAuthenticate); + }); }); }); }