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

Saved Objects Client handle RequestEntityTooLarge error from Elasticsearch #22430

Merged
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
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