Saved Objects Client handle RequestEntityTooLarge error from Elasticsearch (#22430) (#22434)

* Saved Objects Client handle RequestEntityTooLarge error from Elasticsearch

* remove console log
This commit is contained in:
Tim Sullivan 2018-08-28 09:11:52 -07:00 committed by GitHub
parent 8411c02579
commit 48fdc0f51e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View file

@ -28,6 +28,7 @@ const {
Conflict,
401: NotAuthorized,
403: Forbidden,
413: RequestEntityTooLarge,
NotFound,
BadRequest
} = elasticsearch.errors;
@ -36,6 +37,7 @@ import {
decorateBadRequestError,
decorateNotAuthorizedError,
decorateForbiddenError,
decorateRequestEntityTooLargeError,
createGenericNotFoundError,
decorateConflictError,
decorateEsUnavailableError,
@ -69,6 +71,10 @@ export function decorateEsError(error) {
return decorateForbiddenError(error, reason);
}
if (error instanceof RequestEntityTooLarge) {
return decorateRequestEntityTooLargeError(error, reason);
}
if (error instanceof NotFound) {
return createGenericNotFoundError();
}

View file

@ -25,6 +25,7 @@ import {
isConflictError,
isNotAuthorizedError,
isForbiddenError,
isRequestEntityTooLargeError,
isNotFoundError,
isBadRequestError,
} from './errors';
@ -84,6 +85,13 @@ describe('savedObjectsClient/decorateEsError', () => {
expect(isForbiddenError(error)).toBe(true);
});
it('makes es.RequestEntityTooLarge a SavedObjectsClient/RequestEntityTooLarge error', () => {
const error = new esErrors.RequestEntityTooLarge();
expect(isRequestEntityTooLargeError(error)).toBe(false);
expect(decorateEsError(error)).toBe(error);
expect(isRequestEntityTooLargeError(error)).toBe(true);
});
it('discards es.NotFound errors and returns a generic NotFound error', () => {
const error = new esErrors.NotFound();
expect(isNotFoundError(error)).toBe(false);

View file

@ -71,6 +71,16 @@ export function isForbiddenError(error) {
}
// 413 - Request Entity Too Large
const CODE_REQUEST_ENTITY_TOO_LARGE = 'SavedObjectsClient/requestEntityTooLarge';
export function decorateRequestEntityTooLargeError(error, reason) {
return decorate(error, CODE_REQUEST_ENTITY_TOO_LARGE, 413, reason);
}
export function isRequestEntityTooLargeError(error) {
return error && error[code] === CODE_REQUEST_ENTITY_TOO_LARGE;
}
// 404 - Not Found
const CODE_NOT_FOUND = 'SavedObjectsClient/notFound';
export function createGenericNotFoundError(type = null, id = null) {