Bug 1128362 - copr API error responses should use correct error codes
Summary: copr API error responses should use correct error codes
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Copr
Classification: Community
Component: frontend
Version: unspecified
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Kadlčík
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-08-09 14:06 UTC by Jakub Ruzicka
Modified: 2019-02-19 12:43 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-02-19 12:43:54 UTC


Attachments (Terms of Use)

Description Jakub Ruzicka 2014-08-09 14:06:22 UTC
COPR currently returns funny HTTP error codes like:

500 Invalid request

on lack of permissions for selected copr and more. Most of the time, 500 is returned even on client side errors and it's not easy to tell what went wrong.


It would be nice if error responses conatined correct HTTP error code - 4xx for client errors and 5xx for server errors so that error handling/reporting is easier in applications using COPR API.

Comment 1 Adam Samalik 2014-08-11 14:45:20 UTC
Thanks, I'll have a look at that

Comment 2 Jakub Kadlčík 2018-09-17 21:28:39 UTC
We apologize, that this took years, but it is finally done. Meanwhile, both APIv1 (aka Legacy API) and APIv2 (aka REST-like API) are deprecated, so this was implemented in new APIv3. See this example code


    from copr.v3 import Client, CoprRequestException
    client = Client.create_from_config_file()
    client.config["login"] = None # So we can't authorize


    try:
        url = "http://foo.bar/baz.src.rpm"
        client.build_proxy.create_from_url("@copr", "foo", url)
    except CoprRequestException as ex: 
        print(ex.result.__response__.status_code)
        print(ex.message)
         
      
    401 
    Login invalid/expired. Please visit http://localhost:5000/api to get or renew your API token.


Please see the Debugging section in the documentation - https://python-copr.readthedocs.io/en/latest/client_v3/error_handling.html#debugging

There are also described status codes that you can expect, but it was not released yet - https://pagure.io/copr/copr/pull-request/392#request_diff

Comment 3 Jakub Kadlčík 2019-02-19 12:43:54 UTC
A package fixing this issue has been deployed to the production instance.
Also, the list of status codes is now in the documentation - https://python-copr.readthedocs.io/en/latest/client_v3/error_handling.html#status-codes


Note You need to log in before you can comment on or make changes to this bug.