Skip to content

Commit

Permalink
clarify error handling with comments and small variable name refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Apr 8, 2021
1 parent b810dcd commit 3156eb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ interface EsErrorHandlerParams {
handleCustomError?: () => IKibanaResponse<any>;
}

/*
/**
* 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,
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/ingest_pipelines/server/routes/api/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
})
);
Expand Down

0 comments on commit 3156eb6

Please sign in to comment.