Skip to content

Commit

Permalink
Preserving boom error headers for index pattern exceptions (#17725)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb authored Apr 18, 2018
1 parent 2a715c8 commit bf2b6b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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);
});
});
});
}

0 comments on commit bf2b6b0

Please sign in to comment.