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
feat: convert backend chart errors to the new error type #9753
Changes from all commits
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 |
---|---|---|
|
@@ -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) { | ||
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 suspect this new line cause some error_details logged as empty. Can you check what is in err.errors[0].message? |
||
error.error = error.description = error.errors[0].message; | ||
} | ||
|
||
if (error.stack) { | ||
error = { | ||
...error, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# pylint: disable=too-few-public-methods | ||
from enum import Enum | ||
from typing import Any, Dict, Optional | ||
|
||
from dataclasses import dataclass | ||
|
||
|
||
class SupersetErrorType(str, Enum): | ||
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. inheriting from |
||
""" | ||
Types of errors that can exist within Superset. | ||
|
||
Keep in sync with superset-frontend/src/components/ErrorMessage/types.ts | ||
""" | ||
|
||
FRONTEND_CSRF_ERROR = "FRONTEND_CSRF_ERROR" | ||
FRONTEND_NETWORK_ERROR = "FRONTEND_NETWORK_ERROR" | ||
FRONTEND_TIMEOUT_ERROR = "FRONTEND_TIMEOUT_ERROR" | ||
|
||
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. Nit. Nix empty lines? |
||
GENERIC_DB_ENGINE_ERROR = "GENERIC_DB_ENGINE_ERROR" | ||
|
||
VIZ_GET_DF_ERROR = "VIZ_GET_DF_ERROR" | ||
|
||
|
||
class ErrorLevel(str, Enum): | ||
""" | ||
Levels of errors that can exist within Superset. | ||
|
||
Keep in sync with superset-frontend/src/components/ErrorMessage/types.ts | ||
""" | ||
|
||
INFO = "info" | ||
WARNING = "warning" | ||
ERROR = "error" | ||
|
||
|
||
@dataclass | ||
class SupersetError: | ||
""" | ||
An error that is returned to a client. | ||
""" | ||
|
||
message: str | ||
error_type: SupersetErrorType | ||
level: ErrorLevel | ||
extra: Optional[Dict[str, Any]] = None |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ class Datasource(BaseSupersetView): | |
def save(self) -> Response: | ||
data = request.form.get("data") | ||
if not isinstance(data, str): | ||
return json_error_response("Request missing data field.", status="500") | ||
return json_error_response("Request missing data field.", status=500) | ||
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. cleaning up some typing |
||
|
||
datasource_dict = json.loads(data) | ||
datasource_id = datasource_dict.get("id") | ||
|
@@ -66,7 +66,7 @@ def save(self) -> Response: | |
] | ||
if duplicates: | ||
return json_error_response( | ||
f"Duplicate column name(s): {','.join(duplicates)}", status="409" | ||
f"Duplicate column name(s): {','.join(duplicates)}", status=409 | ||
) | ||
orm_datasource.update_from_object(datasource_dict) | ||
data = orm_datasource.data | ||
|
@@ -85,11 +85,11 @@ def get(self, datasource_type: str, datasource_id: int) -> Response: | |
) | ||
if not orm_datasource.data: | ||
return json_error_response( | ||
"Error fetching datasource data.", status="500" | ||
"Error fetching datasource data.", status=500 | ||
) | ||
return self.json_response(orm_datasource.data) | ||
except NoResultFound: | ||
return json_error_response("This datasource does not exist", status="400") | ||
return json_error_response("This datasource does not exist", status=400) | ||
|
||
@expose("/external_metadata/<datasource_type>/<datasource_id>/") | ||
@has_access_api | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Nix empty lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the empty lines here to try and organize these errors into categories, since i expect there to be many of them going forward