public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][patch] pgAdmin4 better exception handling
Date: Wed, 23 Jan 2019 11:01:06 +0530
Message-ID: <CAM9w-_m3O-GHwDTOjjoqVM7xvc6RhX3y6fOdQXyELv1m7a+pdg@mail.gmail.com> (raw)

Hi Hackers,

Attached patch will improve exception handling for pgAdmin4 on the server
side. The app level exception handler will handle unhandled exception
gracefully, logging it and sending the exception message as response.
This will also help in getting the exception where users are facing query
tool initialise error.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"


Attachments:

  [application/octet-stream] pgadmin.errorhandle.patch (1.6K, 3-pgadmin.errorhandle.patch)
  download | inline diff:
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index 1649b2bc..c64245de 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -34,6 +34,8 @@ from pgadmin.utils.session import create_session_interface, pga_unauthorised
 from pgadmin.utils.versioned_template_loader import VersionedTemplateLoader
 from datetime import timedelta
 from pgadmin.setup import get_version, set_version
+from pgadmin.utils.ajax import internal_server_error
+
 
 # If script is running under python3, it will not have the xrange function
 # defined
@@ -662,6 +664,12 @@ def create_app(app_name=None):
             'current_blueprint': current_blueprint
         }
 
+    @app.errorhandler(Exception)
+    def all_exception_handler(e):
+        current_app.logger.error(e)
+        return internal_server_error(errormsg=str(e))
+
+
     ##########################################################################
     # All done!
     ##########################################################################
diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js
index 6de7389f..851d53ff 100644
--- a/web/pgadmin/tools/datagrid/static/js/datagrid.js
+++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js
@@ -438,8 +438,8 @@ define('pgadmin.datagrid', [
               err.errormsg
             );
           } catch (e) {
-            alertify.alert(
-              e.statusText, gettext('Query Tool Initialize Error')
+            alertify.alert(gettext('Query Tool Initialize Error'),
+              e.statusText
             );
           }
         });


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][patch] pgAdmin4 better exception handling
  In-Reply-To: <CAM9w-_m3O-GHwDTOjjoqVM7xvc6RhX3y6fOdQXyELv1m7a+pdg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox