aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-09-21 21:49:32 -0700
committerGitHub <noreply@github.com>2016-09-21 21:49:32 -0700
commite4ae35dabb6fdeb3d9de08c6611f72062fdf0607 (patch)
tree6551658ca8867c9ce36794d0c97b8cbf2ee097fa
parent9e0b935fa241bc50b8c91cbdae32cb1df41ef3f1 (diff)
downloadmitmproxy-e4ae35dabb6fdeb3d9de08c6611f72062fdf0607.tar.gz
mitmproxy-e4ae35dabb6fdeb3d9de08c6611f72062fdf0607.tar.bz2
mitmproxy-e4ae35dabb6fdeb3d9de08c6611f72062fdf0607.zip
fix mitmdump error logging, fix #1549 (#1565)
This commit replaces the logging statement introduced in afe34e8b28988bdff91123862194606152c03c33 with the previous implementation where an exception is raised. ProtocolExceptions are normally logged as regular warnings, achieving the same effect for the end user. However, this retains the full stack trace for debug-level logging, which makes the analysis of client errors considerably easier.
-rw-r--r--mitmproxy/exceptions.py4
-rw-r--r--mitmproxy/protocol/http.py11
-rw-r--r--mitmproxy/proxy/server.py2
3 files changed, 11 insertions, 6 deletions
diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py
index c4797e21..6873215c 100644
--- a/mitmproxy/exceptions.py
+++ b/mitmproxy/exceptions.py
@@ -27,6 +27,10 @@ class Kill(ProxyException):
class ProtocolException(ProxyException):
+ """
+ ProtocolExceptions are caused by invalid user input, unavailable network resources,
+ or other events that are outside of our influence.
+ """
pass
diff --git a/mitmproxy/protocol/http.py b/mitmproxy/protocol/http.py
index 1418d6e9..1632e66f 100644
--- a/mitmproxy/protocol/http.py
+++ b/mitmproxy/protocol/http.py
@@ -153,12 +153,13 @@ class HttpLayer(base.Layer):
# We optimistically guess there might be an HTTP client on the
# other end
self.send_error_response(400, repr(e))
- self.log(
- "request",
- "warn",
- "HTTP protocol error in client request: %s" % e
+ six.reraise(
+ exceptions.ProtocolException,
+ exceptions.ProtocolException(
+ "HTTP protocol error in client request: {}".format(e)
+ ),
+ sys.exc_info()[2]
)
- return
self.log("request", "debug", [repr(request)])
diff --git a/mitmproxy/proxy/server.py b/mitmproxy/proxy/server.py
index 4fd5755a..c5fd5f9e 100644
--- a/mitmproxy/proxy/server.py
+++ b/mitmproxy/proxy/server.py
@@ -132,7 +132,7 @@ class ConnectionHandler(object):
self.log(str(e), "warn")
self.log("Invalid certificate, closing connection. Pass --insecure to disable validation.", "warn")
else:
- self.log(repr(e), "warn")
+ self.log(str(e), "warn")
self.log(traceback.format_exc(), "debug")
# If an error propagates to the topmost level,