Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserving boom error headers for index pattern exceptions #17725

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/server/index_patterns/service/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
11 changes: 11 additions & 0 deletions test/api_integration/apis/index_patterns/es_errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
}