Skip to content

Commit a3173f0

Browse files
committed
improved code
1 parent 6217397 commit a3173f0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def executeQueryJSON(self, procedure, payload=None):
5656
conn = self.__getConnection()
5757

5858
cursor = conn.cursor()
59-
59+
6060
if payload:
6161
cursor.execute(f"EXEC {procedure} ?", json.dumps(payload))
6262
else:
@@ -72,14 +72,16 @@ def executeQueryJSON(self, procedure, payload=None):
7272
cursor.commit()
7373
except pyodbc.Error as e:
7474
if isinstance(e, pyodbc.ProgrammingError) or isinstance(e, pyodbc.OperationalError):
75-
app.logger.error(f"Error: {e.args[0]}")
75+
app.logger.error(f"{e.args[1]}")
7676
if e.args[0] == "08S01":
7777
# If there is a "Communication Link Failure" error,
7878
# then connection must be removed
7979
# as it will be in an invalid state
8080
self.__removeConnection()
8181
raise
82-
82+
finally:
83+
cursor.close()
84+
8385
return result
8486

8587
class Queryable(Resource):

0 commit comments

Comments
 (0)