Skip to content

Commit

Permalink
Friendlier error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Nov 11, 2020
1 parent 9600bd2 commit b7f7243
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion superset-frontend/src/utils/getClientErrorObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export type ClientErrorObject = {
error: string;
errors?: SupersetError[];
link?: string;
message?: string;
// marshmallow field validation returns the error mssage in the format
// of { field: [msg1, msg2] }
message?: string | Record<string, string[]>;
severity?: string;
stacktrace?: string;
} & Partial<SupersetClientResponse>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
.catch(response =>
getClientErrorObject(response).then(error => {
addDangerToast(
t('ERROR: Connection failed. ') + error?.message || '',
error?.message
? `${t('ERROR: ')}${
typeof error.message === 'string'
? error.message
: error.message.sqlalchemy_uri
}`
: t('ERROR: Connection failed. '),
);
}),
);
Expand Down Expand Up @@ -358,6 +364,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
type="text"
name="sqlalchemy_uri"
value={db ? db.sqlalchemy_uri : ''}
autoComplete="off"
placeholder={t(
'dialect+driver://username:password@host:port/database',
)}
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/views/CRUD/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function useSingleViewResource<D extends object = any>(
createErrorHandler(errMsg =>
handleErrorMsg(
t(
'An error occurred while fetching %ss: %s',
'An error occurred while creating %ss: %s',
resourceLabel,
JSON.stringify(errMsg),
),
Expand Down
7 changes: 2 additions & 5 deletions superset/databases/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,8 @@ def sqlalchemy_uri_validator(value: str) -> str:
raise ValidationError(
[
_(
"Invalid connection string, a valid string usually follows:"
"'DRIVER://USER:PASSWORD@DB-HOST/DATABASE-NAME'"
"<p>"
"Example:'postgresql://user:password@your-postgres-db/database'"
"</p>"
"Invalid connection string, a valid string usually follows: "
"dirver://user:password@database-host/database-name"
)
]
)
Expand Down

0 comments on commit b7f7243

Please sign in to comment.