REST machine readable errors - RFC7807 #4088

Closed
opened 2025-12-29 18:33:02 +01:00 by adam · 4 comments
Owner

Originally created by @agowa on GitHub (Sep 9, 2020).

Environment

  • Python version:
  • NetBox version: v2.8.9

Proposed Functionality

Please add machine readable error messages, for example like defined by RFC7807

Use Case

Given the following API call

PUT /api/ipam/ip-addresses/27/?format=json HTTP/1.1
Host: netbox-lab
Authorization: token TokenValue
Content-Type: application/json

{
  "tenant": 2,
  "address": "192.168.178.10/24",
  "id": 27,
  "vrf": 2,
  "dns_name": "vm001.example.com",
  "status": "active",
  "custom_fields": {},
  "interface": 16,
  "tags": [
    "someTag"
  ]
}

the API currently returns this in case of an error:

HTTP/1.1 400 Bad Request
Date: Wed, 09 Sep 2020 16:44:15 GMT
Content-Type: application/json
Content-Length: 110
Connection: close
Server: gunicorn/20.0.4
Vary: Accept, Cookie, Origin
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
API-Version: 2.8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN

{"interface":["IP address is primary for device SomeOtherDevicesName but assigned to None (Network adapter 1)"]}

This error message is hard to handle. It would be much easier if the API follows any standard like e.g. RFC7807.

(To reproduce the above error one just needs a 2nd VM that has the primary IP already assigned before one tries to assign it to another one).

Database Changes

none

External Dependencies

none

Originally created by @agowa on GitHub (Sep 9, 2020). ### Environment * Python version: <!-- Example: 3.6.9 --> * NetBox version: v2.8.9 ### Proposed Functionality Please add machine readable error messages, for example like defined by RFC7807 ### Use Case Given the following API call ``` PUT /api/ipam/ip-addresses/27/?format=json HTTP/1.1 Host: netbox-lab Authorization: token TokenValue Content-Type: application/json { "tenant": 2, "address": "192.168.178.10/24", "id": 27, "vrf": 2, "dns_name": "vm001.example.com", "status": "active", "custom_fields": {}, "interface": 16, "tags": [ "someTag" ] } ``` the API currently returns this in case of an error: ``` HTTP/1.1 400 Bad Request Date: Wed, 09 Sep 2020 16:44:15 GMT Content-Type: application/json Content-Length: 110 Connection: close Server: gunicorn/20.0.4 Vary: Accept, Cookie, Origin Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS API-Version: 2.8 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN {"interface":["IP address is primary for device SomeOtherDevicesName but assigned to None (Network adapter 1)"]} ``` This error message is hard to handle. It would be much easier if the API follows any standard like e.g. RFC7807. (To reproduce the above error one just needs a 2nd VM that has the primary IP already assigned before one tries to assign it to another one). ### Database Changes none ### External Dependencies none
adam closed this issue 2025-12-29 18:33:02 +01:00
Author
Owner

@DanSheps commented on GitHub (Sep 13, 2020):

Can you actually propose a specific change? We aren't going to read through an RFC to extract examples.

@DanSheps commented on GitHub (Sep 13, 2020): Can you actually propose a specific change? We aren't going to read through an RFC to extract examples.
Author
Owner

@agowa commented on GitHub (Sep 14, 2020):

There are examples in the rfc section 3: https://tools.ietf.org/html/rfc7807#section-3

HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
Content-Language: en

{
"type": "https://example.net/validation-error",
"title": "Your request parameters didn't validate.",
"invalid_params": [ {
                      "name": "age",
                      "reason": "must be a positive integer"
                    },
                    {
                      "name": "color",
                      "reason": "must be 'green', 'red' or 'blue'"}
                  ]
}
@agowa commented on GitHub (Sep 14, 2020): There are examples in the rfc section 3: https://tools.ietf.org/html/rfc7807#section-3 ``` HTTP/1.1 400 Bad Request Content-Type: application/problem+json Content-Language: en { "type": "https://example.net/validation-error", "title": "Your request parameters didn't validate.", "invalid_params": [ { "name": "age", "reason": "must be a positive integer" }, { "name": "color", "reason": "must be 'green', 'red' or 'blue'"} ] } ```
Author
Owner

@jeremystretch commented on GitHub (Sep 14, 2020):

The validation errors are primarily a function of the Django REST Framework. This might be worth proposing to that project, but it's not something we can commit development resources to in NetBox.

@jeremystretch commented on GitHub (Sep 14, 2020): The validation errors are primarily a function of the [Django REST Framework](https://www.django-rest-framework.org/). This might be worth proposing to that project, but it's not something we can commit development resources to in NetBox.
Author
Owner

@agowa commented on GitHub (Sep 15, 2020):

From the DRF issue:

It would be more correct to say it is something they don't want to fix.
You can change the default error representation by overriding the default error handler.
(...) We probably could add another error handler that would implement that RFC though and some 3rd party may already implement it

Such a 3rd party library is drf-problems.
https://shivanshs9.me/medium/drf-problems-21f7bb4d4675
https://pypi.org/project/drf-problems/

@agowa commented on GitHub (Sep 15, 2020): From the DRF issue: > It would be more correct to say it is something they don't want to fix. > You can change the default error representation by [overriding the default error handler](https://www.django-rest-framework.org/api-guide/exceptions/#custom-exception-handling). > (...) We probably could add another error handler that would implement that RFC though and some 3rd party may already implement it Such a 3rd party library is drf-problems. https://shivanshs9.me/medium/drf-problems-21f7bb4d4675 https://pypi.org/project/drf-problems/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4088