From fd5e9883b4c4b7c470401e3349724ebdf76d4a5e Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 8 Dec 2020 10:41:19 +0100 Subject: [PATCH] [Transform] fix error wrappers --- x-pack/plugins/transform/server/routes/api/error_utils.ts | 6 +++--- x-pack/plugins/transform/server/routes/api/transforms.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/transform/server/routes/api/error_utils.ts b/x-pack/plugins/transform/server/routes/api/error_utils.ts index cf388f3c8ca08..55e47512c201a 100644 --- a/x-pack/plugins/transform/server/routes/api/error_utils.ts +++ b/x-pack/plugins/transform/server/routes/api/error_utils.ts @@ -76,7 +76,7 @@ export function fillResultsWithTimeouts({ results, id, items, action }: Params) } export function wrapError(error: any): CustomHttpResponseOptions { - const boom = Boom.isBoom(error) ? error : Boom.boomify(error, { statusCode: error.status }); + const boom = Boom.isBoom(error) ? error : Boom.boomify(error, { statusCode: error.statusCode }); return { body: boom, headers: boom.output.headers, @@ -109,14 +109,14 @@ function extractCausedByChain( * @return Object Boom error response */ export function wrapEsError(err: any, statusCodeToMessageMap: Record = {}) { - const { statusCode, response } = err; + const { statusCode, body } = err; const { error: { root_cause = [], // eslint-disable-line @typescript-eslint/naming-convention caused_by = {}, // eslint-disable-line @typescript-eslint/naming-convention } = {}, - } = JSON.parse(response); + } = body; // If no custom message if specified for the error's status code, just // wrap the error as a Boom error response, include the additional information from ES, and return it diff --git a/x-pack/plugins/transform/server/routes/api/transforms.ts b/x-pack/plugins/transform/server/routes/api/transforms.ts index e9f25e4600809..d788fb7c04fa9 100644 --- a/x-pack/plugins/transform/server/routes/api/transforms.ts +++ b/x-pack/plugins/transform/server/routes/api/transforms.ts @@ -108,9 +108,9 @@ export function registerTransformsRoutes(routeDependencies: RouteDependencies) { license.guardApiRoute(async (ctx, req, res) => { const { transformId } = req.params; try { - const { body } = await ctx.core.elasticsearch.client.asCurrentUser.transform.getTransform( - transformId !== undefined ? { transform_id: transformId } : undefined - ); + const { body } = await ctx.core.elasticsearch.client.asCurrentUser.transform.getTransform({ + transform_id: transformId, + }); return res.ok({ body }); } catch (e) { return res.customError(wrapError(wrapEsError(e)));