Fixed unclosed prepared database queries blocking server. Added better error checking and bad request fallbacks to webapp

This commit is contained in:
Daniel Ledda
2020-11-28 09:05:59 +01:00
parent 785e40d0ec
commit 1f2df8b069
3 changed files with 38 additions and 35 deletions

View File

@@ -30,6 +30,10 @@ func writeSnapshotToDb(snapshotSub *SnapshotSubmission) (int64, error) {
queryStr := "INSERT INTO `snapshots` (`temp`, `humidity`, `co2`, `time`, `id`) VALUES (?, ?, ?, ?, NULL);"
query, err := ClimateDb.Prepare(queryStr)
if err != nil {
closeErr := query.Close()
if closeErr != nil {
return -1, fmt.Errorf("couldn't prepare snapshot query: %w. (also failed to close: %s)", err, closeErr.Error())
}
return -1, fmt.Errorf("couldn't prepare snapshot query: %w", err)
}
result, err := query.Exec(