🐛 Improve network error message (#106246)
This commit is contained in:
parent
ec30f2aeeb
commit
33bf0fe633
|
@ -141,6 +141,17 @@ const scriptedFieldError = {
|
|||
},
|
||||
};
|
||||
|
||||
const networkError = {
|
||||
stack: 'Error: Batch request failed with status 0',
|
||||
message: '[lens_merge_tables] > [esaggs] > Batch request failed with status 0',
|
||||
name: 'Error',
|
||||
original: {
|
||||
name: 'Error',
|
||||
message: 'Batch request failed with status 0',
|
||||
stack: 'Error: Batch request failed with status 0',
|
||||
},
|
||||
};
|
||||
|
||||
// EsAggs will report an internal error when user attempts to use a runtime field on an indexpattern he has no access to
|
||||
const indexpatternAccessError = {
|
||||
stack: "TypeError: Cannot read property 'values' of undefined\n",
|
||||
|
@ -175,5 +186,11 @@ describe('lens_error_helpers', () => {
|
|||
indexpatternAccessError.message,
|
||||
]);
|
||||
});
|
||||
|
||||
it("should report a network custom message when there's a network/connection problem", () => {
|
||||
expect(getOriginalRequestErrorMessages(networkError as Error)).toEqual([
|
||||
'Network error, try again later or contact your administrator.',
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -28,6 +28,10 @@ interface EsAggError {
|
|||
stack: string;
|
||||
}
|
||||
|
||||
const isNetworkError = (e: Error): boolean => {
|
||||
return e.message === 'Batch request failed with status 0'; // Note: 0 here means Network error
|
||||
};
|
||||
|
||||
const isRequestError = (e: Error | RequestError): e is RequestError => {
|
||||
if ('body' in e) {
|
||||
return e.body?.attributes?.error?.caused_by !== undefined;
|
||||
|
@ -101,7 +105,15 @@ export function getOriginalRequestErrorMessages(error?: ExpressionRenderError |
|
|||
const errorMessages = [];
|
||||
if (error && 'original' in error && error.original) {
|
||||
if (isEsAggError(error.original)) {
|
||||
errorMessages.push(error.message);
|
||||
if (isNetworkError(error.original)) {
|
||||
errorMessages.push(
|
||||
i18n.translate('xpack.lens.editorFrame.networkErrorMessage', {
|
||||
defaultMessage: 'Network error, try again later or contact your administrator.',
|
||||
})
|
||||
);
|
||||
} else {
|
||||
errorMessages.push(error.message);
|
||||
}
|
||||
} else {
|
||||
const rootErrors = uniqWith(getErrorSources(error.original), isEqual);
|
||||
for (const rootError of rootErrors) {
|
||||
|
|
Loading…
Reference in a new issue