Skip to content

Commit

Permalink
[index patterns] Don't attempt to wrap Boom errors (#14253) (#14265)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjoar authored Oct 3, 2017
1 parent c3c161e commit 6819311
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.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);
});
});
});
}

0 comments on commit 6819311

Please sign in to comment.