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

[6.x] [index patterns] Don't attempt to wrap Boom errors (#14253) #14263

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.wrap(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
@@ -1,5 +1,6 @@
import expect from 'expect.js';
import { errors as esErrors } from 'elasticsearch';
import Boom from 'boom';

import {
isEsIndexNotFoundError,
Expand Down Expand Up @@ -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);
});
});
});
}