* [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>
21 lines
767 B
TypeScript
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,
|
|
};
|
|
}
|