Open
Description
Some exceptions cause that circuits.web
doesn't response at all:
#!/usr/bin/env python
from circuits import Component, Debugger, handler
from circuits.web import Server
from circuits.web.controllers import BaseController, expose
from circuits.web.errors import httperror
class Foo(Component):
@handler("response", priority=1.0)
def foo(self, event, response):
event[0] = httperror(response.request, response, 404, description='foo, bar')
class Root(BaseController):
@expose("index")
def index(self):
return "Hello World!"
app = Server(("0.0.0.0", 8000))
Root().register(app)
Foo().register(app)
Debugger().register(app)
app.run()
<request[web] (<Request GET / HTTP/1.1>, <Response 200 OK None (0)> )>
<index[/] (<Request GET / HTTP/1.1>, <Response 200 OK None (0)> )>
<request_success[web] (<request[web] (<Request GET / HTTP/1.1>, <Response 200 OK None (0)> )>, None )>
<request_complete[web] (<request[web] (<Request GET / HTTP/1.1>, <Response 200 OK None (0)> )>, 'Hello World!' )>
<response[web] (<Response 200 OK None (0)> )>
<response_failure[web] (<response[web] (<httperror 404 Not Found> )>, (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'headers'"), <traceback object at 0x7fa0ca1281c8>) )>
<exception[web] (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'headers'"), handler=<bound method HTTP._on_response of <HTTP/web 26963:MainThread (queued=0) [S]>>, fevent=<response[web] (<httperror 404 Not Found> )>)>
ERROR <handler[*][response] (HTTP._on_response)> (<response[web] (<httperror 404 Not Found> )>) (<class 'AttributeError'>): AttributeError("'httperror' object has no attribute 'headers'")
Traceback (most recent call last):
File "/home/git/circuits/circuits/core/manager.py", line 679, in _dispatcher
value = event_handler(*eargs, **ekwargs)
File "/home/git/circuits/circuits/web/http.py", line 148, in _on_response
headers = res.headers
AttributeError: 'httperror' object has no attribute 'headers'
<exception[web] (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'done'"), handler=<bound method HTTP._on_response_failure of <HTTP/web 26963:MainThread (queued=0) [S]>>, fevent=<response_failure[web] (<response[web] (<httperror 404 Not Found> )>, (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'headers'"), <traceback object at 0x7fa0ca1281c8>) )>)>
ERROR <handler[*][response_failure] (HTTP._on_response_failure)> (<response_failure[web] (<response[web] (<httperror 404 Not Found> )>, (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'headers'"), <traceback
object at 0x7fa0ca1281c8>) )>) (<class 'AttributeError'>): AttributeError("'httperror' object has no attribute 'done'")
Traceback (most recent call last):
File "/home/git/circuits/circuits/core/manager.py", line 679, in _dispatcher
value = event_handler(*eargs, **ekwargs)
File "/home/git/circuits/circuits/web/http.py", line 491, in _on_response_failure
if res.done:
AttributeError: 'httperror' object has no attribute 'done'
<httperror 500 Internal Server Error>
<exception[web] (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'headers'"), handler=<bound method HTTP._on_httperror of <HTTP/web 26963:MainThread (queued=0) [S]>>, fevent=<httperror 500 Internal Server Error>)>
ERROR <handler[*][httperror] (HTTP._on_httperror)> (<httperror 500 Internal Server Error>) (<class 'AttributeError'>): AttributeError("'httperror' object has no attribute 'headers'")
Traceback (most recent call last):
File "/home/git/circuits/circuits/core/manager.py", line 677, in _dispatcher
value = event_handler(event, *eargs, **ekwargs)
File "/home/git/circuits/circuits/web/http.py", line 322, in _on_httperror
res.body = str(event)
File "/home/git/circuits/circuits/web/errors.py", line 81, in __str__
self.sanitize()
File "/home/git/circuits/circuits/web/errors.py", line 77, in sanitize
if "Location" in self.response.headers:
AttributeError: 'httperror' object has no attribute 'headers'
<response_complete[web] (<response[web] (<httperror 404 Not Found> )>, (<class 'AttributeError'>, AttributeError("'httperror' object has no attribute 'headers'"), <traceback object at 0x7fa0ca1281c8>) )>
<_read[web] (<socket.socket fd=6, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 8000), raddr=('127.0.0.1', 47600)> )>
<disconnect[web] (<socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0> )>
This usage is actually used in the compressed example, which return in error conditions a httperror instead of a response.
Maybe httperror should be supported, maybe not.
At least in that case, a response must be send!
Metadata
Metadata
Assignees
Labels
No labels