kibana/x-pack/plugins/ml/server/client/error_wrapper.ts
James Gowdy 64f27ca34e
[ML] Show better file structure finder explanations (#62316)
* [ML] Show better file structure finder explanations

* more typescript changes

* changing function format

* fixing some types

* fixing translation id

* fix boom error reporting

* changes based on review

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2020-04-07 08:47:39 +01:00

21 lines
767 B
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { boomify, isBoom } from 'boom';
import { ResponseError, CustomHttpResponseOptions } from 'kibana/server';
export function wrapError(error: any): CustomHttpResponseOptions<ResponseError> {
const boom = isBoom(error) ? error : boomify(error, { statusCode: error.status });
const statusCode = boom.output.statusCode;
return {
body: {
message: boom,
...(statusCode !== 500 && error.body ? { attributes: { body: error.body } } : {}),
},
headers: boom.output.headers,
statusCode,
};
}