Skip to content

Commit

Permalink
[ILM] Add type casting for ResponseError
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Oct 16, 2020
1 parent 268d165 commit 4885988
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { ApiError } from '@elastic/elasticsearch';
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { IKibanaResponse, KibanaResponseFactory } from 'kibana/server';

interface EsErrorHandlerParams {
Expand All @@ -31,12 +32,10 @@ interface EsErrorHandlerParams {
export const handleEsError = ({ error, response }: EsErrorHandlerParams): IKibanaResponse => {
// error.name is slightly better in terms of performance, since all errors now have name property
if (error.name === 'ResponseError') {
const { statusCode, body } = error as ResponseError;
return response.customError({
// we can ignore typescript error, since error is a ResponseError
// @ts-ignore
statusCode: error.statusCode,
// @ts-ignore
body: { message: error.body.error?.reason },
statusCode,
body: { message: body.error?.reason },
});
}
// Case: default
Expand Down

0 comments on commit 4885988

Please sign in to comment.