Add exception logging

This commit is contained in:
Michael Lazar 2020-05-18 01:40:19 -04:00
parent 78e94f3091
commit f02ea37762
1 changed files with 3 additions and 0 deletions

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import time import time
import traceback
import typing import typing
import urllib.parse import urllib.parse
@ -89,6 +90,7 @@ class GeminiProtocol(LineOnlyReceiver):
self.parse_header() self.parse_header()
except Exception: except Exception:
# Malformed request, throw it away and exit immediately # Malformed request, throw it away and exit immediately
self.server.log_message(traceback.format_exc())
self.write_status(Status.BAD_REQUEST, "Malformed request") self.write_status(Status.BAD_REQUEST, "Malformed request")
self.flush_status() self.flush_status()
self.transport.loseConnection() self.transport.loseConnection()
@ -106,6 +108,7 @@ class GeminiProtocol(LineOnlyReceiver):
except StopIteration: except StopIteration:
break break
except Exception: except Exception:
self.server.log_message(traceback.format_exc())
self.write_status(Status.CGI_ERROR, "An unexpected error occurred") self.write_status(Status.CGI_ERROR, "An unexpected error occurred")
finally: finally:
self.flush_status() self.flush_status()