From 3156eb6914d1dc59c8babc594d3030ff3c85ad57 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Thu, 8 Apr 2021 10:48:24 +0200 Subject: [PATCH] clarify error handling with comments and small variable name refactor --- .../__packages_do_not_import__/errors/handle_es_error.ts | 4 +++- x-pack/plugins/ingest_pipelines/server/routes/api/get.ts | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/es_ui_shared/__packages_do_not_import__/errors/handle_es_error.ts b/src/plugins/es_ui_shared/__packages_do_not_import__/errors/handle_es_error.ts index 42e18b72057ce3..6a308203fcc279 100644 --- a/src/plugins/es_ui_shared/__packages_do_not_import__/errors/handle_es_error.ts +++ b/src/plugins/es_ui_shared/__packages_do_not_import__/errors/handle_es_error.ts @@ -17,8 +17,10 @@ interface EsErrorHandlerParams { handleCustomError?: () => IKibanaResponse; } -/* +/** * For errors returned by the new elasticsearch js client. + * + * @throws If "error" is not an error from the elasticsearch client this handler will throw "error". */ export const handleEsError = ({ error, diff --git a/x-pack/plugins/ingest_pipelines/server/routes/api/get.ts b/x-pack/plugins/ingest_pipelines/server/routes/api/get.ts index f03fb39b30ee48..853bd1c7dde238 100644 --- a/x-pack/plugins/ingest_pipelines/server/routes/api/get.ts +++ b/x-pack/plugins/ingest_pipelines/server/routes/api/get.ts @@ -31,11 +31,13 @@ export const registerGetRoutes = ({ return res.ok({ body: deserializePipelines(pipelines) }); } catch (error) { - const errorResponse = handleEsError({ error, response: res }); - if (errorResponse.status === 404) { + const esErrorResponse = handleEsError({ error, response: res }); + if (esErrorResponse.status === 404) { + // ES returns 404 when there are no pipelines + // Instead, we return an empty array and 200 status back to the client return res.ok({ body: [] }); } - return errorResponse; + return esErrorResponse; } }) );