villebro commented on a change in pull request #9178: [core] Fix, sanitize 
errors returned from testconn
URL: 
https://github.com/apache/incubator-superset/pull/9178#discussion_r382086135
 
 

 ##########
 File path: superset/views/core.py
 ##########
 @@ -1330,11 +1335,32 @@ def testconn(self):
             with closing(engine.connect()) as conn:
                 conn.scalar(select([1]))
                 return json_success('"OK"')
-        except Exception as e:
-            logger.exception(e)
+        except NoSuchModuleError as e:
+            logger.info(f"Invalid driver {e}")
+            driver_name = make_url(uri).drivername
             return json_error_response(
-                "Connection failed!\n\n" f"The error message returned 
was:\n{e}", 400
+                _(
+                    "Could not load database driver: %(driver_name)s",
+                    driver_name=driver_name,
+                ),
+                400,
             )
+        except ArgumentError as e:
+            logger.info(f"Invalid URI {e}")
+            return json_error_response(
+                _(
+                    "Invalid connnection string, a valid string follows: \n"
+                    " 'DRIVER://USER:PASSWORD@DB-HOST/DATABASE-NAME'"
+                )
+            )
+        except OperationalError as e:
+            logger.warning(f"Connection failed {e}")
+            return json_error_response(
+                _("Connection failed, please check your connection 
settings."), 400
+            )
+        except Exception as e:
+            logger.error(f"Unexpected error {e}")
 
 Review comment:
   Same here

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to