Add invalid response object error handling
This commit is contained in:
parent
6cf3754051
commit
68f6553181
|
@ -21,6 +21,10 @@ class ServerError(SanicException):
|
||||||
status_code = 500
|
status_code = 500
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidResponseObject(SanicException):
|
||||||
|
status_code = 500
|
||||||
|
|
||||||
|
|
||||||
class FileNotFound(NotFound):
|
class FileNotFound(NotFound):
|
||||||
status_code = 404
|
status_code = 404
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ from signal import SIGINT, SIGTERM
|
||||||
from time import time
|
from time import time
|
||||||
from httptools import HttpRequestParser
|
from httptools import HttpRequestParser
|
||||||
from httptools.parser.errors import HttpParserError
|
from httptools.parser.errors import HttpParserError
|
||||||
from .exceptions import ServerError
|
from .exceptions import ServerError, InvalidResponseObject
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import uvloop as async_loop
|
import uvloop as async_loop
|
||||||
|
@ -150,9 +150,14 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
try:
|
try:
|
||||||
keep_alive = self.parser.should_keep_alive() \
|
keep_alive = self.parser.should_keep_alive() \
|
||||||
and not self.signal.stopped
|
and not self.signal.stopped
|
||||||
self.transport.write(
|
try:
|
||||||
response.output(
|
self.transport.write(
|
||||||
self.request.version, keep_alive, self.request_timeout))
|
response.output(
|
||||||
|
self.request.version, keep_alive,
|
||||||
|
self.request_timeout))
|
||||||
|
except AttributeError:
|
||||||
|
raise InvalidResponseObject(
|
||||||
|
'Invalid response object, must be of type HTTPResponse')
|
||||||
if not keep_alive:
|
if not keep_alive:
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user