-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Lens] Leverage original http request error #79831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
926fbae
a0b1958
20710c8
9073897
b7d33a7
521e932
a8cf08f
0b2aaa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
|
||
| [Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionRenderError](./kibana-plugin-plugins-expressions-public.expressionrendererror.md) > [original](./kibana-plugin-plugins-expressions-public.expressionrendererror.original.md) | ||
|
|
||
| ## ExpressionRenderError.original property | ||
|
|
||
| <b>Signature:</b> | ||
|
|
||
| ```typescript | ||
| original?: Error; | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,9 @@ import { ExpressionValueError } from '../../common'; | |
|
|
||
| type ErrorLike = Partial<Pick<Error, 'name' | 'message' | 'stack'>>; | ||
|
|
||
| export const createError = (err: string | Error | ErrorLike): ExpressionValueError => ({ | ||
| export const createError = ( | ||
| err: string | Error | ErrorLike | ExpressionValueError['error'] | ||
| ): ExpressionValueError => ({ | ||
| type: 'error', | ||
| error: { | ||
| stack: | ||
|
|
@@ -32,6 +34,11 @@ export const createError = (err: string | Error | ErrorLike): ExpressionValueErr | |
| : undefined, | ||
| message: typeof err === 'string' ? err : String(err.message), | ||
| name: typeof err === 'object' ? err.name || 'Error' : 'Error', | ||
| original: err instanceof Error ? err : undefined, | ||
| original: | ||
| err instanceof Error | ||
| ? err | ||
| : typeof err === 'object' && 'original' in err && err.original instanceof Error | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could leverage some knowledge from TS here and just do ...
: err.original instanceof Error ? err.original : undefined
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is necessary because |
||
| ? err.original | ||
| : undefined, | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||
| /* | ||||
| * 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 { i18n } from '@kbn/i18n'; | ||||
|
|
||||
| import { ExpressionRenderError } from 'src/plugins/expressions/public'; | ||||
|
|
||||
| interface RequestError extends Error { | ||||
| body?: { attributes?: { error: { caused_by: { type: string; reason: string } } } }; | ||||
| } | ||||
|
|
||||
| const isRequestError = (e: Error | RequestError): e is RequestError => { | ||||
| if ('body' in e) { | ||||
| return e.body?.attributes?.error?.caused_by !== undefined; | ||||
| } | ||||
| return false; | ||||
| }; | ||||
|
|
||||
| export function getOriginalRequestErrorMessage(error?: ExpressionRenderError | null) { | ||||
| return ( | ||||
| error && | ||||
| 'original' in error && | ||||
| error.original && | ||||
| isRequestError(error.original) && | ||||
| i18n.translate('xpack.lens.editorFrame.expressionFailureMessage', { | ||||
| defaultMessage: 'Request error: {causedByType}, {causedByReason}', | ||||
| values: { | ||||
| causedByType: error.original.body?.attributes?.error?.caused_by.type, | ||||
| causedByReason: error.original.body?.attributes?.error?.caused_by.reason, | ||||
|
||||
| if (isRequestError(error)) { |
I totally see your point, but I don’t think we have a “handleAllCommonEsErrors” helper (yet). What do you think about adding nice handling for the cases you mention above (great findings btw), and if none of these apply falling back to the default behavior of unknown errors (which is showing the message of the thrown exception and also what’s happening on master right now) - at least for 7.10. We should continue to investigate to find a holistic solution and ideally roll it out everywhere (Discover, Visualize etc - all of them produce really bad error messages depending on the case)
I’m also more than happy to loop in someone knowledgeable on the topic to improve the PR beyond what’s mentioned above (do you know who would be a good fit?), my only ask is to not increase scope too much for an improvement of the current state of 7.10 (that’s also why I didn’t touch core code itself to refactor out a generic helper, it felt like opening a can of worms too big for the scope of the intended fix).
Uh oh!
There was an error while loading. Please reload this page.