Mercurial > prosody-modules
diff mod_mam_sql/mod_mam_sql.lua @ 1206:04bf76c3e4c6
mod_mam_sql: Add better error handling
author | Rob Hoelz <rob@hoelz.ro> |
---|---|
date | Mon, 02 Sep 2013 19:55:51 +0200 |
parents | 1e0d273bcb75 |
children | c6b8ae5a8369 |
line wrap: on
line diff
--- a/mod_mam_sql/mod_mam_sql.lua Sun Oct 06 17:30:21 2013 +0200 +++ b/mod_mam_sql/mod_mam_sql.lua Mon Sep 02 19:55:51 2013 +0200 @@ -114,13 +114,20 @@ if params.driver == "PostgreSQL" then sql = sql:gsub("`", "\""); end + if not connection then + return nil, 'connection failed'; + end -- do prepared statement stuff local stmt, err = connection:prepare(sql); - if not stmt and not test_connection() then error("connection failed"); end + if not stmt and not test_connection() then + return nil, "connection failed"; + end if not stmt then module:log("error", "QUERY FAILED: %s %s", err, debug.traceback()); return nil, err; end -- run query local ok, err = stmt:execute(...); - if not ok and not test_connection() then error("connection failed"); end + if not ok and not test_connection() then + return nil, "connection failed"; + end if not ok then return nil, err; end return stmt;