forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
77 lines (64 loc) · 1.73 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { HttpFetchError } from 'kibana/public';
import Boom from '@hapi/boom';
export interface EsErrorRootCause {
type: string;
reason: string;
caused_by?: EsErrorRootCause;
script?: string;
}
export interface EsErrorBody {
error: {
root_cause?: EsErrorRootCause[];
caused_by?: EsErrorRootCause;
type: string;
reason: string;
};
status: number;
}
export interface MLResponseError {
statusCode: number;
error: string;
message: string;
attributes?: {
body: EsErrorBody;
};
}
export interface ErrorMessage {
message: string;
}
export interface MLErrorObject {
causedBy?: string;
message: string;
statusCode?: number;
fullError?: EsErrorBody;
}
export interface MLHttpFetchError<T> extends HttpFetchError {
body: T;
}
export type ErrorType =
| MLHttpFetchError<MLResponseError>
| EsErrorBody
| Boom.Boom
| string
| undefined;
export function isEsErrorBody(error: any): error is EsErrorBody {
return error && error.error?.reason !== undefined;
}
export function isErrorString(error: any): error is string {
return typeof error === 'string';
}
export function isErrorMessage(error: any): error is ErrorMessage {
return error && error.message !== undefined && typeof error.message === 'string';
}
export function isMLResponseError(error: any): error is MLResponseError {
return typeof error.body === 'object' && 'message' in error.body;
}
export function isBoomError(error: any): error is Boom.Boom {
return error?.isBoom === true;
}