Feature #1232
closedAPI: Error/Exception Handling
Description
API Error/Exception Handling. Implemented error codes:
400: The request is invalid. The body or parameters are wrong.
401: You failed to authenticate with the server.
403: You don't have the permission to access the requested resource. Please authenticate with the server, either through login via the user interface or token based authentication.
404: Something went wrong! Maybe only digits are allowed. Please check the URL
404a: The requested entity doesn't exist. Try another ID
404b: The syntax is incorrect. Only digits are allowed. For further usage, please confer the help page
404c: The syntax is incorrect. Valid codes are: actor, event, place, source, reference and object. For further usage, please confer the help page.
404d: The syntax is incorrect. These class code is not supported. For the classes please confer the model.
404e: The syntax is incorrect. Only integers between 1 and 100 are allowed.
405: The method used is not supported. Right now only GET is allowed.
500: Please notify the administrator. Sorry for the inconvenience.
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Description updated (diff)
- Subject changed from Error Handling to Error/Exception Handling
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Status changed from New to Assigned
Updated by Alexander Watzinger over 4 years ago
- Target version set to 208
Good idea, we could try to use the backend error views located at views/index.py. If we differentiate in these functions if the call is from API and e.g. don't use the templates it could be easily called inside the API with e.g.
abort(404)
As for which we need: I think 404 (not found) and 403 (forbidden) would be the most essential ones. You can see what else is already implemented for the backend at views/index.py.
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Status changed from Assigned to In Progress
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Status changed from In Progress to Resolved
A first model for the API error handling is finished and run through nosetests. @Alexander Watzinger: do you want to look it through in the feature_api branch or should I just merge it to develop?
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Target version changed from 208 to 5.3.0
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Status changed from Resolved to Closed
I pushed it to develop.
Updated by Alexander Watzinger over 4 years ago
- Subject changed from Error/Exception Handling to API: Error/Exception Handling
Updated by Alexander Watzinger over 4 years ago
- Status changed from Closed to In Progress
Reopening this issue because tests still didn't passed in the develop branch.
One issue that was really hard to track down (turned out it occurs only if the route begins with "/api") was that in index.py API errors tried to return something like
APIError('Forbidden', status_code="403").to_dict()
which caused an error, I fixed it for now with casting it to a string like:
str(APIError('Forbidden', status_code="403").to_dict())
but not sure if this is what you wanted or needed so please take a look at it.
Also the 404b error is still comment out because 'actor' is passed as argument where an int is expected and not handled properly.
Sadly our last fixes didn't made it to the develop branch (they seemed to be made only in some API branch) so I fixed it in develop (again). Please, make sure that develop tests are passing at all times and also take care with latest changes because you surly will get merge conflicts after work was done in different branches.
Please keep this issue open until everything is straightened out, if finished (merged in develop and all tests pass as expected) assign it to me with a comment. I will test again on my machine because as we noticed last time, some errors don't seem to show up on your machine.
Updated by Bernhard Koschiček-Krombholz over 4 years ago
Thank you, Alex, for your work.
I had no chance to look into it and I had also no chance to merge it to develop. I will do this Tuesday 16.06., but I have to look into our changes we made.
APIError('Forbidden', status_code="403").to_dict()
This SHOULD return a json, so the machine-readable content. I will look into it. Again, the soonest possible day is Tuesday 16.06.
For the 404b, it is gone, but as you noticed, I didn't merged it into develop. Before I merge our changes, I have to clean up, because some of our changes brings new errors, because they aren't fully complete (i.e. #1206).
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Assignee changed from Bernhard Koschiček-Krombholz to Alexander Watzinger
@Alexander Watzinger: can you please check if the test will work now? It is under the feature_api branch.
But maybe we can get together after your holidays, because it is hard to fix an error, which I can't replicate.
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Target version changed from 5.3.0 to 208
Updated by Alexander Watzinger over 4 years ago
- Assignee changed from Alexander Watzinger to Bernhard Koschiček-Krombholz
All tests and Mypy checks are working, even in the newest develop version. Assigning back.
Updated by Bernhard Koschiček-Krombholz over 4 years ago
- Status changed from In Progress to Closed
- Target version changed from 208 to 5.3.0
The error handling is for now sufficient and covers every API error occurrence. Thanks to Alex for testing.