commit 445886fb8539557ce084bac354ee27cefc452370
Author: David Friesecký <frieseck@students.zcu.cz>
Date:   Mon May 17 10:26:36 2021 +0200

    Re #8884 - Improved exceptions in repositories

diff --git a/src/dao/certificate_repository.py b/src/dao/certificate_repository.py
index 2e42509..c71a6a4 100644
--- a/src/dao/certificate_repository.py
+++ b/src/dao/certificate_repository.py
@@ -88,26 +88,10 @@ class CertificateRepository:
                         values = [last_id, usage_id]
                         self.cursor.execute(sql, values)
                         self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError as e:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            # TODO will be improved in #8884
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
             Logger.error(str(e))
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+            raise DatabaseException(e)
 
         return last_id
 
@@ -159,24 +143,9 @@ class CertificateRepository:
                                                    certificate_row[11],     # revocation date
                                                    certificate_row[12])     # revocation reason
 
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return certificate
 
@@ -233,24 +202,10 @@ class CertificateRepository:
                                                 certificate_row[10],     # email address
                                                 certificate_row[11],     # revocation date
                                                 certificate_row[12]))    # revocation reason
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return certificates
 
@@ -324,24 +279,10 @@ class CertificateRepository:
                                                 certificate_row[10],  # email address
                                                 certificate_row[11],  # revocation date
                                                 certificate_row[12]))  # revocation reason
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return certificates
 
@@ -411,24 +352,10 @@ class CertificateRepository:
                     values = [certificate_id, usage_id]
                     self.cursor.execute(sql, values)
                     self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return check_updated
 
@@ -451,24 +378,10 @@ class CertificateRepository:
                       certificate_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return self.cursor.rowcount > 0
 
@@ -503,24 +416,10 @@ class CertificateRepository:
                       certificate_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return self.cursor.rowcount > 0
 
@@ -545,24 +444,10 @@ class CertificateRepository:
             values = [certificate_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return self.cursor.rowcount > 0
 
@@ -616,24 +501,10 @@ class CertificateRepository:
                                                 certificate_row[10],     # email address
                                                 certificate_row[11],     # revocation date
                                                 certificate_row[12]))    # revocation reason
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return certificates
 
@@ -688,24 +559,10 @@ class CertificateRepository:
                                                 certificate_row[10],     # email address
                                                 certificate_row[11],     # revocation date
                                                 certificate_row[12]))    # revocation reason
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return certificates
 
@@ -784,24 +641,10 @@ class CertificateRepository:
                                                 certificate_row[10],  # email address
                                                 certificate_row[11],  # revocation date
                                                 certificate_row[12]))  # revocation reason
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return certificates
 
@@ -827,24 +670,10 @@ class CertificateRepository:
 
             all_certs = []
             dfs(self.get_all_issued_by, subtree_root, all_certs)
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return all_certs
 
@@ -866,23 +695,9 @@ class CertificateRepository:
                 if result[0] == TAB_CERTIFICATES:
                     return result[1] + 1  # current last id + 1
             # if certificates table is not present in the query results, return 1
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return 1
diff --git a/src/dao/private_key_repository.py b/src/dao/private_key_repository.py
index 57f1b32..1d11e37 100644
--- a/src/dao/private_key_repository.py
+++ b/src/dao/private_key_repository.py
@@ -49,24 +49,10 @@ class PrivateKeyRepository:
             self.cursor.execute(sql, values)
             last_id = self.cursor.lastrowid
             self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return last_id
 
@@ -92,24 +78,10 @@ class PrivateKeyRepository:
             private_key: PrivateKey = PrivateKey(private_key_row[0],
                                                  private_key_row[1],
                                                  private_key_row[2])
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return private_key
 
@@ -171,24 +143,10 @@ class PrivateKeyRepository:
                 private_keys.append(PrivateKey(private_key_row[0],
                                                private_key_row[1],
                                                private_key_row[2]))
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return private_keys
 
@@ -212,24 +170,10 @@ class PrivateKeyRepository:
                       private_key_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return self.cursor.rowcount > 0
 
@@ -248,23 +192,9 @@ class PrivateKeyRepository:
             values = [private_key_id]
             self.cursor.execute(sql, values)
             self.connection.commit()
-        except IntegrityError:
-            Logger.error(INTEGRITY_ERROR_MSG)
-            raise DatabaseException(INTEGRITY_ERROR_MSG)
-        except ProgrammingError:
-            Logger.error(PROGRAMMING_ERROR_MSG)
-            raise DatabaseException(PROGRAMMING_ERROR_MSG)
-        except OperationalError:
-            Logger.error(OPERATIONAL_ERROR_MSG)
-            raise DatabaseException(OPERATIONAL_ERROR_MSG)
-        except NotSupportedError:
-            Logger.error(NOT_SUPPORTED_ERROR_MSG)
-            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
-        except DatabaseError:
-            Logger.error(DATABASE_ERROR_MSG)
-            raise DatabaseException(DATABASE_ERROR_MSG)
-        except Error:
-            Logger.error(ERROR_MSG)
-            raise DatabaseException(ERROR_MSG)
+
+        except (IntegrityError, OperationalError, ProgrammingError, NotSupportedError, DatabaseError, Error) as e:
+            Logger.error(str(e))
+            raise DatabaseException(e)
 
         return self.cursor.rowcount > 0
