kibana/x-pack/plugins/ml/common/util/errors.ts
James Gowdy 0236376fa9
[ML] Fixing reporting of http request errors (#61811)
* [ML] Fixing reporting of http request errors

* fixing types

* updating translations

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2020-03-31 11:44:01 +01:00

19 lines
572 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 { isErrorResponse } from '../types/errors';
export function getErrorMessage(error: any) {
if (isErrorResponse(error)) {
return `${error.body.error}: ${error.body.message}`;
}
if (typeof error === 'object' && typeof error.message === 'string') {
return error.message;
}
return JSON.stringify(error);
}