Bug 1128362

Summary: copr API error responses should use correct error codes
Product: [Community] Copr Reporter: Jakub Ruzicka <jruzicka>
Component: frontendAssignee: Jakub Kadlčík <jkadlcik>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: clime, msuchy
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-02-19 12:43:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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