Project

General

Profile

Actions

Feature #1232

closed

API: Error/Exception Handling

Added by Bernhard Koschiček-Krombholz almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Category:
API
Target version:
Start date:
2020-05-10
Estimated time:

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.

Actions #1

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Description updated (diff)
  • Subject changed from Error Handling to Error/Exception Handling
Actions #2

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Status changed from New to Assigned
Actions #3

Updated by Alexander Watzinger almost 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.

Actions #4

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Status changed from Assigned to In Progress
Actions #5

Updated by Bernhard Koschiček-Krombholz almost 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?

Actions #6

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Target version changed from 208 to 5.3.0
Actions #7

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Status changed from Resolved to Closed

I pushed it to develop.

Actions #8

Updated by Alexander Watzinger almost 4 years ago

  • Subject changed from Error/Exception Handling to API: Error/Exception Handling
Actions #9

Updated by Alexander Watzinger almost 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.

Actions #10

Updated by Bernhard Koschiček-Krombholz almost 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).

Actions #11

Updated by Bernhard Koschiček-Krombholz almost 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.

Actions #12

Updated by Bernhard Koschiček-Krombholz almost 4 years ago

  • Target version changed from 5.3.0 to 208
Actions #13

Updated by Alexander Watzinger almost 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.

Actions #14

Updated by Bernhard Koschiček-Krombholz almost 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.

Actions #15

Updated by Alexander Watzinger almost 4 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF