pyeve / eve

REST API framework designed for human beings
https://python-eve.org
Other
6.71k stars 745 forks source link

API errors swallowed #904

Closed jakul closed 7 years ago

jakul commented 8 years ago

Hiya,

I'm having problems getting (some of) the system-wide error handlers to work properly. My specific problem is that when I try to DELETE a resource without sending an ETag I get the following error:

# HTML removed
<!--

Traceback (most recent call last):
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/eve/flaskapp.py", line 968, in __call__
    return super(Eve, self).__call__(environ, start_response)
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1539, in handle_user_exception
    return self.handle_http_exception(e)
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1495, in handle_http_exception
    handler = self._find_error_handler(e)
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1476, in _find_error_handler
    .get(code))
  File "/Users/craig/.virtualenvs/service-intel/lib/python2.7/site-packages/flask/app.py", line 1465, in find_handler
    handler = handler_map.get(cls)
AttributeError: 'function' object has no attribute 'get'

-->

I am expecting this response:

$ http DELETE http://127.0.0.1:5003/facebook_ads_api_authentication/57bb1e05bd130b7232004dd6
HTTP/1.0 403 FORBIDDEN
Content-Length: 101
Content-Type: application/json
Date: Mon, 22 Aug 2016 16:17:55 GMT
Server: Eve/0.6.4 Werkzeug/0.11.3 Python/2.7.10

{
    "_error": {
        "code": 403,
        "message": "An etag must be provided to edit a document"
    },
    "_status": "ERR"
}

I am using Flask 0.11.1 and Eve 0.6.4.

Possible solution

I think the cause of the problem is that you are registering the generic error handler to Flask in a way which is discouraged. I think that this code is wrong.

    def register_error_handlers(self):
        """ Register custom error handlers so we make sure that all errors
        return a parseable body.
        .. versionadded:: 0.4
        """
        for code in self.config['STANDARD_ERRORS']:
            self.error_handler_spec[None][code] = error_endpoint

Here's what I think it should be:


    def register_error_handlers(self):
        """ Register custom error handlers so we make sure that all errors
        return a parseable body.

        .. versionadded:: 0.4
        """
        for code in self.config['STANDARD_ERRORS']:
            self.register_error_handler(code, error_endpoint)

Craig.

lambasoft commented 8 years ago

Im having the same issue currently. Im following tutorial at http://code.tutsplus.com/tutorials/building-rest-apis-using-eve--cms-22961

nicolaiarocci commented 8 years ago

Hello, on which version are you both? On 0.7 I get:

{
  "_status": "ERR",
  "_error": {
    "message": "To edit a document its etag must be provided using the If-Match header",
    "code": 428
  }
}
jakul commented 8 years ago

0.6.4. 0.7 is unreleased so I can't use it in production

nicolaiarocci commented 7 years ago

@jakul on which flask version are you? Could it be 0.11? There's a known incompatibility between flask 0.11 and Eve right now (fix coming up, see #945).

jakul commented 7 years ago

Yup, Flask 0.11.4

nicolaiarocci commented 7 years ago

Can you please try and downgrade flask to 0.10.1 and see if this fixes the issue for you? Eve is currently pinned at 0.10.1 so it should not happen that it installs flask 0.11 on setup.

nicolaiarocci commented 7 years ago

Should be fixed.