Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b3c80ccb

Přidáno uživatelem David Friesecký před téměř 4 roky(ů)

Re #8570 - Added logs

Zobrazit rozdíly:

src/dao/private_key_repository.py
1
from sqlite3 import Connection, Cursor, Error
1
from sqlite3 import Connection, Error, DatabaseError, IntegrityError, ProgrammingError, OperationalError, NotSupportedError
2 2
from typing import List
3 3

  
4 4
from injector import inject
......
6 6
from src.exceptions.database_exception import DatabaseException
7 7
from src.model.private_key import PrivateKey
8 8
from src.constants import *
9
from src.utils.logger import Logger
10

  
11
INTEGRITY_ERROR_MSG = "Database relational integrity corrupted."
12
PROGRAMMING_ERROR_MSG = "Exception raised for programming errors (etc. SQL statement)."
13
OPERATIONAL_ERROR_MSG = "Exception raised for errors that are related to the database’s operation."
14
NOT_SUPPORTED_ERROR_MSG = "Method or database API was used which is not supported by the database"
15
DATABASE_ERROR_MSG = "Unknown exception that are related to the database."
16
ERROR_MSG = "Unknown exception."
9 17

  
10 18

  
11 19
class PrivateKeyRepository:
......
41 49
            self.cursor.execute(sql, values)
42 50
            last_id = self.cursor.lastrowid
43 51
            self.connection.commit()
44
        except Error as e:
45
            raise DatabaseException(e)
52
        except IntegrityError:
53
            Logger.error(INTEGRITY_ERROR_MSG)
54
            raise DatabaseException(INTEGRITY_ERROR_MSG)
55
        except ProgrammingError:
56
            Logger.error(PROGRAMMING_ERROR_MSG)
57
            raise DatabaseException(PROGRAMMING_ERROR_MSG)
58
        except OperationalError:
59
            Logger.error(OPERATIONAL_ERROR_MSG)
60
            raise DatabaseException(OPERATIONAL_ERROR_MSG)
61
        except NotSupportedError:
62
            Logger.error(NOT_SUPPORTED_ERROR_MSG)
63
            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
64
        except DatabaseError:
65
            Logger.error(DATABASE_ERROR_MSG)
66
            raise DatabaseException(DATABASE_ERROR_MSG)
67
        except Error:
68
            Logger.error(ERROR_MSG)
69
            raise DatabaseException(ERROR_MSG)
46 70

  
47 71
        return last_id
48 72

  
......
68 92
            private_key: PrivateKey = PrivateKey(private_key_row[0],
69 93
                                                 private_key_row[1],
70 94
                                                 private_key_row[2])
71
        except Error as e:
72
            raise DatabaseException(e)
95
        except IntegrityError:
96
            Logger.error(INTEGRITY_ERROR_MSG)
97
            raise DatabaseException(INTEGRITY_ERROR_MSG)
98
        except ProgrammingError:
99
            Logger.error(PROGRAMMING_ERROR_MSG)
100
            raise DatabaseException(PROGRAMMING_ERROR_MSG)
101
        except OperationalError:
102
            Logger.error(OPERATIONAL_ERROR_MSG)
103
            raise DatabaseException(OPERATIONAL_ERROR_MSG)
104
        except NotSupportedError:
105
            Logger.error(NOT_SUPPORTED_ERROR_MSG)
106
            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
107
        except DatabaseError:
108
            Logger.error(DATABASE_ERROR_MSG)
109
            raise DatabaseException(DATABASE_ERROR_MSG)
110
        except Error:
111
            Logger.error(ERROR_MSG)
112
            raise DatabaseException(ERROR_MSG)
73 113

  
74 114
        return private_key
75 115

  
......
90 130
                private_keys.append(PrivateKey(private_key_row[0],
91 131
                                               private_key_row[1],
92 132
                                               private_key_row[2]))
93
        except Error as e:
94
            raise DatabaseException(e)
133
        except IntegrityError:
134
            Logger.error(INTEGRITY_ERROR_MSG)
135
            raise DatabaseException(INTEGRITY_ERROR_MSG)
136
        except ProgrammingError:
137
            Logger.error(PROGRAMMING_ERROR_MSG)
138
            raise DatabaseException(PROGRAMMING_ERROR_MSG)
139
        except OperationalError:
140
            Logger.error(OPERATIONAL_ERROR_MSG)
141
            raise DatabaseException(OPERATIONAL_ERROR_MSG)
142
        except NotSupportedError:
143
            Logger.error(NOT_SUPPORTED_ERROR_MSG)
144
            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
145
        except DatabaseError:
146
            Logger.error(DATABASE_ERROR_MSG)
147
            raise DatabaseException(DATABASE_ERROR_MSG)
148
        except Error:
149
            Logger.error(ERROR_MSG)
150
            raise DatabaseException(ERROR_MSG)
95 151

  
96 152
        return private_keys
97 153

  
......
115 171
                      private_key_id]
116 172
            self.cursor.execute(sql, values)
117 173
            self.connection.commit()
118
        except Error as e:
119
            raise DatabaseException(e)
174
        except IntegrityError:
175
            Logger.error(INTEGRITY_ERROR_MSG)
176
            raise DatabaseException(INTEGRITY_ERROR_MSG)
177
        except ProgrammingError:
178
            Logger.error(PROGRAMMING_ERROR_MSG)
179
            raise DatabaseException(PROGRAMMING_ERROR_MSG)
180
        except OperationalError:
181
            Logger.error(OPERATIONAL_ERROR_MSG)
182
            raise DatabaseException(OPERATIONAL_ERROR_MSG)
183
        except NotSupportedError:
184
            Logger.error(NOT_SUPPORTED_ERROR_MSG)
185
            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
186
        except DatabaseError:
187
            Logger.error(DATABASE_ERROR_MSG)
188
            raise DatabaseException(DATABASE_ERROR_MSG)
189
        except Error:
190
            Logger.error(ERROR_MSG)
191
            raise DatabaseException(ERROR_MSG)
120 192

  
121 193
        return self.cursor.rowcount > 0
122 194

  
......
135 207
            values = [private_key_id]
136 208
            self.cursor.execute(sql, values)
137 209
            self.connection.commit()
138
        except Error as e:
139
            raise DatabaseException
210
        except IntegrityError:
211
            Logger.error(INTEGRITY_ERROR_MSG)
212
            raise DatabaseException(INTEGRITY_ERROR_MSG)
213
        except ProgrammingError:
214
            Logger.error(PROGRAMMING_ERROR_MSG)
215
            raise DatabaseException(PROGRAMMING_ERROR_MSG)
216
        except OperationalError:
217
            Logger.error(OPERATIONAL_ERROR_MSG)
218
            raise DatabaseException(OPERATIONAL_ERROR_MSG)
219
        except NotSupportedError:
220
            Logger.error(NOT_SUPPORTED_ERROR_MSG)
221
            raise DatabaseException(NOT_SUPPORTED_ERROR_MSG)
222
        except DatabaseError:
223
            Logger.error(DATABASE_ERROR_MSG)
224
            raise DatabaseException(DATABASE_ERROR_MSG)
225
        except Error:
226
            Logger.error(ERROR_MSG)
227
            raise DatabaseException(ERROR_MSG)
140 228

  
141 229
        return self.cursor.rowcount > 0

Také k dispozici: Unified diff