Skip to content

Commit e140e1b

Browse files
committed
Gracefully handle errors during early request binding.
1 parent e1be22d commit e140e1b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

bottle.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -848,17 +848,19 @@ def default_error_handler(self, res):
848848
return tob(template(ERROR_PAGE_TEMPLATE, e=res))
849849

850850
def _handle(self, environ):
851-
path = environ['bottle.raw_path'] = environ['PATH_INFO']
852-
if py3k:
853-
try:
854-
environ['PATH_INFO'] = path.encode('latin1').decode('utf8')
855-
except UnicodeError:
856-
return HTTPError(400, 'Invalid path string. Expected UTF-8')
857-
858851
try:
852+
859853
environ['bottle.app'] = self
860854
request.bind(environ)
861855
response.bind()
856+
857+
path = environ['bottle.raw_path'] = environ['PATH_INFO']
858+
if py3k:
859+
try:
860+
environ['PATH_INFO'] = path.encode('latin1').decode('utf8')
861+
except UnicodeError:
862+
return HTTPError(400, 'Invalid path string. Expected UTF-8')
863+
862864
try:
863865
self.trigger_hook('before_request')
864866
route, args = self.router.match(environ)

0 commit comments

Comments
 (0)