From 1982ee6e46b41ffcbada3a739c323c7763e275f5 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Thu, 29 Apr 2021 18:02:41 -0500 Subject: [PATCH] Report insufficient permission errors --- src/pgwui_upload_core/exceptions.py | 6 ++++++ src/pgwui_upload_core/views/upload.py | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/pgwui_upload_core/exceptions.py b/src/pgwui_upload_core/exceptions.py index 8025357..ef173d8 100644 --- a/src/pgwui_upload_core/exceptions.py +++ b/src/pgwui_upload_core/exceptions.py @@ -65,3 +65,9 @@ class BadHeadersError(SetupError): '''The headers in the uploaded file are bad.''' def __init__(self, e, descr='', detail=''): super(BadHeadersError, self).__init__(e, descr, detail) + + +class InsufficientPrivilegeError(SetupError): + '''The privileges are not sufficent to perform the requested operation''' + def __init__(self, e, descr='', detail=''): + super().__init__(e, descr, detail) diff --git a/src/pgwui_upload_core/views/upload.py b/src/pgwui_upload_core/views/upload.py index dacd51d..97459ad 100644 --- a/src/pgwui_upload_core/views/upload.py +++ b/src/pgwui_upload_core/views/upload.py @@ -170,6 +170,10 @@ class BaseTableUploadHandler(TabularFileUploadHandler): ('

Hint: Check spelling, database permissions, ' ' or try qualifying the' ' table name with a schema name

')) + elif pgcode == psycopg2.errorcodes.INSUFFICIENT_PRIVILEGE: + raise upload_ex.InsufficientPrivilegeError( + 'Your PostgreSQL login has insufficient privileges', + err.diag.message_primary) else: raise return self.cur.fetchone() -- 2.34.1