Preserving boom error headers for index pattern exceptions (#17725) (#17775)

This commit is contained in:
Brandon Kobel 2018-04-18 13:48:29 -04:00 committed by GitHub
parent 6748c6abbd
commit acd99a13c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -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 });

View file

@ -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);
});
});
});
}