Project

General

Profile

Feature #1232

API: Error/Exception Handling

Added by Bernhard Koschicek 6 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Low
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.

History

#1

Updated by Bernhard Koschicek 6 months ago

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

Updated by Bernhard Koschicek 6 months ago

  • Status changed from New to Assigned
#3

Updated by Alexander Watzinger 6 months ago

  • Target version set to API

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.

#4

Updated by Bernhard Koschicek 5 months ago

  • Status changed from Assigned to In Progress
#5

Updated by Bernhard Koschicek 5 months 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?

#6

Updated by Bernhard Koschicek 5 months ago

  • Target version changed from API to 5.3.0
#7

Updated by Bernhard Koschicek 5 months ago

  • Status changed from Resolved to Closed

I pushed it to develop.

#8

Updated by Alexander Watzinger 5 months ago

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

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

#10

Updated by Bernhard Koschicek 5 months 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).

#11

Updated by Bernhard Koschicek 5 months ago

  • Assignee changed from Bernhard Koschicek 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.

#12

Updated by Bernhard Koschicek 4 months ago

  • Target version changed from 5.3.0 to API
#13

Updated by Alexander Watzinger 4 months ago

  • Assignee changed from Alexander Watzinger to Bernhard Koschicek

All tests and Mypy checks are working, even in the newest develop version. Assigning back.

#14

Updated by Bernhard Koschicek 4 months ago

  • Target version changed from API to 5.3.0
  • Status changed from In Progress to Closed

The error handling is for now sufficient and covers every API error occurrence. Thanks to Alex for testing.

#15

Updated by Alexander Watzinger 4 months ago

  • Description updated (diff)

Also available in: Atom PDF