main.lua: Log upstream HTTP errors

Mon, 04 Jan 2016 11:03:31 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 04 Jan 2016 11:03:31 +0000
changeset 2
13a1d5e43a2b
parent 1
7eff79ea9a01
child 3
8d3d5d8afbad

main.lua: Log upstream HTTP errors

main.lua file | annotate | diff | comparison | revisions
--- a/main.lua	Sun Jan 03 17:30:35 2016 +0000
+++ b/main.lua	Mon Jan 04 11:03:31 2016 +0000
@@ -5,6 +5,7 @@
 local server = require "net.server_select";
 local http = require "net.http";
 local logger = require "util.logger";
+local log = logger.init("main");
 events = require "util.events".new();
 
 require "clients";
@@ -18,6 +19,10 @@
 
 events.add_handler("have-clients", function ()
 	request = http.request(arg[1], {success_on_chunk=true}, function (data, code, response)
+		if code ~= 200 then
+			log("error", "Error from upstream: %s", tostring(code));
+			return;
+		end
 		local boundary = response.headers["content-type"]:match("; boundary=(.+)$").."\r\n";
 		if #data > #boundary and data:sub(1, #boundary) ~= boundary then
 			print(string.format(("%02X "):rep(6), data:byte(1,6)));

mercurial