feat: convert backend chart errors to the new error type (#9753)

This commit is contained in:
Erik Ritter
2020-05-12 18:15:53 -07:00
committed by GitHub
parent 0e7888c659
commit 83ec7365a7
15 changed files with 175 additions and 33 deletions

View File

@@ -18,12 +18,14 @@
*/
import { SupersetClientResponse } from '@superset-ui/connection';
import { t } from '@superset-ui/translation';
import { SupersetError } from 'src/components/ErrorMessage/types';
import COMMON_ERR_MESSAGES from './errorMessages';
// The response always contains an error attribute, can contain anything from the
// SupersetClientResponse object, and can contain a spread JSON blob
export type ClientErrorObject = {
error: string;
errors?: SupersetError[];
severity?: string;
message?: string;
stacktrace?: string;
@@ -48,6 +50,12 @@ export default function getClientErrorObject(
.json()
.then(errorJson => {
let error = { ...responseObject, ...errorJson };
// Backwards compatibility for old error renderers with the new error object
if (error.errors && error.errors.length > 0) {
error.error = error.description = error.errors[0].message;
}
if (error.stack) {
error = {
...error,