Skip to content

Commit

Permalink
[Transform] fix error wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Dec 8, 2020
1 parent 4e44a09 commit fd5e988
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions x-pack/plugins/transform/server/routes/api/error_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function fillResultsWithTimeouts({ results, id, items, action }: Params)
}

export function wrapError(error: any): CustomHttpResponseOptions<ResponseError> {
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,
Expand Down Expand Up @@ -109,14 +109,14 @@ function extractCausedByChain(
* @return Object Boom error response
*/
export function wrapEsError(err: any, statusCodeToMessageMap: Record<string, any> = {}) {
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
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/transform/server/routes/api/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export function registerTransformsRoutes(routeDependencies: RouteDependencies) {
license.guardApiRoute<TransformIdParamSchema, undefined, undefined>(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)));
Expand Down

0 comments on commit fd5e988

Please sign in to comment.