[index patterns] Don't attempt to wrap Boom errors (#14253) (#14265)

This commit is contained in:
Kim Joar Bekkelund 2017-10-03 18:25:08 +02:00 committed by GitHub
parent c3c161e29a
commit 6819311ec8
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.wrap(error, statusCode, message);

View file

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