Skip to content

Commit

Permalink
Saved Objects Client handle RequestEntityTooLarge error from Elastics…
Browse files Browse the repository at this point in the history
…earch (#22430)

* Saved Objects Client handle RequestEntityTooLarge error from Elasticsearch

* remove console log
  • Loading branch information
tsullivan authored Aug 27, 2018
1 parent 8ccd456 commit 73d5909
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/server/saved_objects/service/lib/decorate_es_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
Conflict,
401: NotAuthorized,
403: Forbidden,
413: RequestEntityTooLarge,
NotFound,
BadRequest
} = elasticsearch.errors;
Expand All @@ -36,6 +37,7 @@ import {
decorateBadRequestError,
decorateNotAuthorizedError,
decorateForbiddenError,
decorateRequestEntityTooLargeError,
createGenericNotFoundError,
decorateConflictError,
decorateEsUnavailableError,
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
isConflictError,
isNotAuthorizedError,
isForbiddenError,
isRequestEntityTooLargeError,
isNotFoundError,
isBadRequestError,
} from './errors';
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/server/saved_objects/service/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 73d5909

Please sign in to comment.