Changeset

1158:ae1767b54964

mod_auth_external: Fix logging of errors
author Matthew Wild <mwild1@gmail.com>
date Tue, 13 Aug 2013 23:36:40 +0100
parents 1157:a7d0d129df6f
children 1159:c56a1d449cad
files mod_auth_external/mod_auth_external.lua
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_auth_external/mod_auth_external.lua	Tue Aug 13 21:37:05 2013 +0100
+++ b/mod_auth_external/mod_auth_external.lua	Tue Aug 13 23:36:40 2013 +0100
@@ -58,19 +58,17 @@
 		query = query..'\n';
 	end
 	
-	local response = send_query(query);
-	if (script_type == "ejabberd" and response == "\0\2\0\0") or
+	local response, err = send_query(query);
+	if not response then
+		log("warn", "Error while waiting for result from auth process: %s", err or "unknown error");
+	elseif (script_type == "ejabberd" and response == "\0\2\0\0") or
 		(script_type == "generic" and response:gsub("\r?\n$", "") == "0") then
 			return nil, "not-authorized";
 	elseif (script_type == "ejabberd" and response == "\0\2\0\1") or
 		(script_type == "generic" and response:gsub("\r?\n$", "") == "1") then
 			return true;
 	else
-		if response then
-			log("warn", "Unable to interpret data from auth process, %s", (response:match("^error:") and response) or ("["..#response.." bytes]"));
-		else
-			log("warn", "Error while waiting for result from auth process: %s", response or "unknown error");
-		end
+		log("warn", "Unable to interpret data from auth process, %s", (response:match("^error:") and response) or ("["..#response.." bytes]"));
 		return nil, "internal-server-error";
 	end
 end