prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Remove responder exception handling
  Can hide problems, encourage bad coding practices.
  
  
  </issue>
  <code>
  [start of falcon/api.py]
  1 """Defines the API class.
  2 
  3 Copyright 2013 by Rackspace Hosting, Inc.
  4 
  5 Licensed under the Apache License, Version 2.0 (the "License");
  6 you may not use this file except in compliance with the License.
  7 You may obtain a copy of the License at
  8 
  9    http://www.apache.org/licenses/LICENSE-2.0
  10 
  11 Unless required by applicable law or agreed to in writing, software
  12 distributed under the License is distributed on an "AS IS" BASIS,
  13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 See the License for the specific language governing permissions and
  15 limitations under the License.
  16 
  17 """
  18 
  19 import traceback
  20 
  21 from .request import Request
  22 from .response import Response
  23 from . import responders
  24 from .status_codes import *
  25 from .api_helpers import *
  26 
  27 from .http_error import HTTPError
  28 
  29 
  30 class API(object):
  31     """Provides routing and such for building a web service application
  32 
  33     This class is the main entry point into a Falcon-based app. It provides a
  34     callable WSGI interface and a simple routing engine based on URI templates.
  35 
  36     """
  37 
  38     __slots__ = ('_routes')
  39 
  40     def __init__(self):
  41         """Initialize default values"""
  42         self._routes = []
  43 
  44     def __call__(self, env, start_response):
  45         """WSGI "app" method
  46 
  47         Makes instances of API callable by any WSGI server. See also PEP 333.
  48 
  49         Args:
  50             env: A WSGI environment dictionary
  51             start_response: A WSGI helper method for setting status and headers
  52                 on a response.
  53 
  54         """
  55 
  56         req = Request(env)
  57         resp = Response()
  58 
  59         responder, params = self._get_responder(req.path, req.method)
  60 
  61         try:
  62             responder(req, resp, **params)
  63 
  64         except HTTPError as ex:
  65             resp.status = ex.status
  66             if ex.headers is not None:
  67                 resp.set_headers(ex.headers)
  68 
  69             if req.client_accepts_json():
  70                 resp.body = ex.json()
  71 
  72         except Exception as ex:
  73             # Reset to a known state and respond with a generic error
  74             req = Request(env)
  75             resp = Response()
  76 
  77             message = ['Responder raised ', ex.__class__.__name__]
  78 
  79             details = str(ex)
  80             if details:
  81                 message.append(': ')
  82                 message.append(details)
  83 
  84             stack = traceback.format_exc()
  85             message.append('\n')
  86             message.append(stack)
  87 
  88             req.log_error(''.join(message))
  89             responders.server_error(req, resp)
  90 
  91         #
  92         # Set status and headers
  93         #
  94         use_body = not should_ignore_body(resp.status, req.method)
  95         if use_body:
  96             set_content_length(resp)
  97 
  98         start_response(resp.status, resp._wsgi_headers())
  99 
  100         # Return an iterable for the body, per the WSGI spec
  101         if use_body:
  102             return prepare_wsgi_content(resp)
  103 
  104         # Default: return an empty body
  105         return []
  106 
  107     def add_route(self, uri_template, resource):
  108         """Associate a URI path with a resource
  109 
  110         Args:
  111             uri_template: Relative URI template. Currently only Level 1
  112                 templates are supported. See also RFC 6570.
  113             resource: Object which represents an HTTP/REST "resource". Falcon
  114                 will pass "GET" requests to on_get, "PUT" requests to on_put,
  115                 etc. If any HTTP methods are not supported by your resource,
  116                 simply don't define the corresponding request handlers, and
  117                 Falcon will do the right thing.
  118 
  119         """
  120 
  121         if not uri_template:
  122             uri_template = '/'
  123 
  124         path_template = compile_uri_template(uri_template)
  125         method_map = create_http_method_map(resource)
  126 
  127         # Insert at the head of the list in case we get duplicate
  128         # adds (will cause the last one to win).
  129         self._routes.insert(0, (path_template, method_map))
  130 
  131     def _get_responder(self, path, method):
  132         """Searches routes for a matching responder
  133 
  134         Args:
  135             path: URI path to search (without query stirng)
  136             method: HTTP method (uppercase) requested
  137         Returns:
  138             A 2-member tuple, containing a responder callable and a dict
  139             containing parsed path fields, if any were specified in
  140             the matching route's URI template
  141 
  142         """
  143 
  144         for path_template, method_map in self._routes:
  145             m = path_template.match(path)
  146             if m:
  147                 params = m.groupdict()
  148 
  149                 try:
  150                     responder = method_map[method]
  151                 except KeyError:
  152                     responder = responders.bad_request
  153 
  154                 break
  155         else:
  156             responder = responders.path_not_found
  157             params = {}
  158 
  159         return (responder, params)
  160
  [end of falcon/api.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/falcon/api.py b/falcon/api.py
  --- a/falcon/api.py
  +++ b/falcon/api.py
  @@ -16,8 +16,6 @@
   
   """
   
  -import traceback
  -
   from .request import Request
   from .response import Response
   from . import responders
  @@ -69,25 +67,6 @@
               if req.client_accepts_json():
                   resp.body = ex.json()
   
  -        except Exception as ex:
  -            # Reset to a known state and respond with a generic error
  -            req = Request(env)
  -            resp = Response()
  -
  -            message = ['Responder raised ', ex.__class__.__name__]
  -
  -            details = str(ex)
  -            if details:
  -                message.append(': ')
  -                message.append(details)
  -
  -            stack = traceback.format_exc()
  -            message.append('\n')
  -            message.append(stack)
  -
  -            req.log_error(''.join(message))
  -            responders.server_error(req, resp)
  -
           #
           # Set status and headers
           #
  
verification_info: {"golden_diff": "diff --git a/falcon/api.py b/falcon/api.py\n--- a/falcon/api.py\n+++ b/falcon/api.py\n@@ -16,8 +16,6 @@\n \n \"\"\"\n \n-import traceback\n-\n from .request import Request\n from .response import Response\n from . import responders\n@@ -69,25 +67,6 @@\n             if req.client_accepts_json():\n                 resp.body = ex.json()\n \n-        except Exception as ex:\n-            # Reset to a known state and respond with a generic error\n-            req = Request(env)\n-            resp = Response()\n-\n-            message = ['Responder raised ', ex.__class__.__name__]\n-\n-            details = str(ex)\n-            if details:\n-                message.append(': ')\n-                message.append(details)\n-\n-            stack = traceback.format_exc()\n-            message.append('\\n')\n-            message.append(stack)\n-\n-            req.log_error(''.join(message))\n-            responders.server_error(req, resp)\n-\n         #\n         # Set status and headers\n         #\n", "issue": "Remove responder exception handling\nCan hide problems, encourage bad coding practices.\n\n", "before_files": [{"content": "\"\"\"Defines the API class.\n\nCopyright 2013 by Rackspace Hosting, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\"\"\"\n\nimport traceback\n\nfrom .request import Request\nfrom .response import Response\nfrom . import responders\nfrom .status_codes import *\nfrom .api_helpers import *\n\nfrom .http_error import HTTPError\n\n\nclass API(object):\n    \"\"\"Provides routing and such for building a web service application\n\n    This class is the main entry point into a Falcon-based app. It provides a\n    callable WSGI interface and a simple routing engine based on URI templates.\n\n    \"\"\"\n\n    __slots__ = ('_routes')\n\n    def __init__(self):\n        \"\"\"Initialize default values\"\"\"\n        self._routes = []\n\n    def __call__(self, env, start_response):\n        \"\"\"WSGI \"app\" method\n\n        Makes instances of API callable by any WSGI server. See also PEP 333.\n\n        Args:\n            env: A WSGI environment dictionary\n            start_response: A WSGI helper method for setting status and headers\n                on a response.\n\n        \"\"\"\n\n        req = Request(env)\n        resp = Response()\n\n        responder, params = self._get_responder(req.path, req.method)\n\n        try:\n            responder(req, resp, **params)\n\n        except HTTPError as ex:\n            resp.status = ex.status\n            if ex.headers is not None:\n                resp.set_headers(ex.headers)\n\n            if req.client_accepts_json():\n                resp.body = ex.json()\n\n        except Exception as ex:\n            # Reset to a known state and respond with a generic error\n            req = Request(env)\n            resp = Response()\n\n            message = ['Responder raised ', ex.__class__.__name__]\n\n            details = str(ex)\n            if details:\n                message.append(': ')\n                message.append(details)\n\n            stack = traceback.format_exc()\n            message.append('\\n')\n            message.append(stack)\n\n            req.log_error(''.join(message))\n            responders.server_error(req, resp)\n\n        #\n        # Set status and headers\n        #\n        use_body = not should_ignore_body(resp.status, req.method)\n        if use_body:\n            set_content_length(resp)\n\n        start_response(resp.status, resp._wsgi_headers())\n\n        # Return an iterable for the body, per the WSGI spec\n        if use_body:\n            return prepare_wsgi_content(resp)\n\n        # Default: return an empty body\n        return []\n\n    def add_route(self, uri_template, resource):\n        \"\"\"Associate a URI path with a resource\n\n        Args:\n            uri_template: Relative URI template. Currently only Level 1\n                templates are supported. See also RFC 6570.\n            resource: Object which represents an HTTP/REST \"resource\". Falcon\n                will pass \"GET\" requests to on_get, \"PUT\" requests to on_put,\n                etc. If any HTTP methods are not supported by your resource,\n                simply don't define the corresponding request handlers, and\n                Falcon will do the right thing.\n\n        \"\"\"\n\n        if not uri_template:\n            uri_template = '/'\n\n        path_template = compile_uri_template(uri_template)\n        method_map = create_http_method_map(resource)\n\n        # Insert at the head of the list in case we get duplicate\n        # adds (will cause the last one to win).\n        self._routes.insert(0, (path_template, method_map))\n\n    def _get_responder(self, path, method):\n        \"\"\"Searches routes for a matching responder\n\n        Args:\n            path: URI path to search (without query stirng)\n            method: HTTP method (uppercase) requested\n        Returns:\n            A 2-member tuple, containing a responder callable and a dict\n            containing parsed path fields, if any were specified in\n            the matching route's URI template\n\n        \"\"\"\n\n        for path_template, method_map in self._routes:\n            m = path_template.match(path)\n            if m:\n                params = m.groupdict()\n\n                try:\n                    responder = method_map[method]\n                except KeyError:\n                    responder = responders.bad_request\n\n                break\n        else:\n            responder = responders.path_not_found\n            params = {}\n\n        return (responder, params)\n", "path": "falcon/api.py"}]}