Page 1 of 1

API returns wrong status code on failure

Posted: Sat Jun 08, 2019 2:42 am
by sib
Hi

The API does not return the correct HTTP Status codes on failure. This returns HTTP 200 even though there is an error

Version: 5.6.2

Code: Select all

}, 
    "json": {
        "error": "Missing required variables", 
        "missing": [
            "host_name", 
            "service_description", 
            "max_check_attempts", 
            "check_interval", 
            "retry_interval", 
            "check_period", 
            "notification_interval", 
            "notification_period", 
            "contacts OR contact_groups"
        ]
    }, 
    "msg": "OK (230 bytes)",

Re: API returns wrong status code on failure

Posted: Mon Jun 10, 2019 12:33 pm
by npolovenko
Hello, @sib. The HTTP 200 OK status means that the HTTP request has been processed successfully. While the error below indicates that Nagios will not be able to add the service because some required fields were missing. But this is a separate logic. From the HTTP standpoint, the request went through successfully.

Re: API returns wrong status code on failure

Posted: Mon Jun 10, 2019 1:27 pm
by sib
Hi

I still think this is missleading. It should be a 4xx i.e Bad Request error if the request has missing mandatory fields.

Re: API returns wrong status code on failure

Posted: Mon Jun 10, 2019 2:43 pm
by npolovenko
@sib, I understand. I'm going to submit a feature request on your behalf to add this functionality.
Please keep in mind that the decision to implement the enhancement is at the discretion of our development team.
Let me know if you have any other API related concerns.

Re: API returns wrong status code on failure

Posted: Mon Jun 10, 2019 2:59 pm
by sib
Hi

No other questions. Thanks for the RFE

Re: API returns wrong status code on failure

Posted: Mon Jun 10, 2019 3:50 pm
by npolovenko
@sib, No problem. Closing this thread as resolved.