-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix API v2 exception on incorrect API key. Fixes #5425 #6703
Conversation
DeepCode analyzed this pull request. Click to see more details. |
Working on implementing a couple of tests, and another small bug:
|
Ooh then ignore my approval |
Sorry, took me a while to figure all of this stuff out. I think the code for the multi-threaded API looks much better now. edit: oh come on... |
This reverts commit b291939.
- Fix requests getting logged twice. - Fix API v2 HTTPErrors getting logged as warnings.
All good now. |
except Exception as error: | ||
self._handle_request_exception(error) | ||
result = self._check_authentication() | ||
return method(*args, **kwargs) if result is None else result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your kinda asuming that the method call cant raise exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to explain as best I can.
Basically - yes.
But the difference is the RequestHandler
class has an exception handler, and we handle everything in write_error
now.
Medusa/medusa/server/api/v2/base.py
Lines 151 to 165 in 91140e1
def write_error(self, status_code, *args, **kwargs): | |
"""Only send traceback if app.DEVELOPER is true.""" | |
response = None | |
exc_info = kwargs.get('exc_info', None) | |
if exc_info and isinstance(exc_info[1], HTTPError): | |
error = exc_info[1].log_message or exc_info[1].reason | |
response = self.api_response(status=status_code, error=error) | |
elif app.DEVELOPER and exc_info: | |
self.set_header('content-type', 'text/plain') | |
self.set_status(500) | |
for line in traceback.format_exception(*exc_info): | |
self.write(line) | |
else: | |
response = self._internal_server_error() |
HTTPErrors
are handled as RESTful responses,
And anything other than HTTPError
is handled as an actual exception and sends "Internal Server Error" as the response (or the traceback, if app.DEVELOPER
is enabled, like before)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your kinda asuming that the method call cant raise exceptions?
Sorry, I actually misread that.
Quite the opposite, I plan on it, but as I explained in the comment above, it's all being handled (just in one location and not everywhere)
Retry Deepcode |
DeepCode analyzed this pull request. Click to see more details. |
…usa#6703) * Fix API v2 exception on incorrect API key. Fixes pymedusa#5425 * Update changelog * Fix authentication endpoint * Test bad auth conditions * Fix RESTful and non-RESTful error handling * Fix API pagination This reverts commit b291939. * Fix Tornado request logging - Fix requests getting logged twice. - Fix API v2 HTTPErrors getting logged as warnings. * Fix `write_error` for `raise HTTPError(code, message)`
Fixes #5425, added 2 small tests for that
Fixes RESTful
HTTPError
s causing real exceptions.