Univention Bugzilla – Bug 50249
Improve error response format
Last modified: 2022-12-14 15:04:46 CET
The error response format of the UDM REST API is currently like the following: # http --auth Administrator:univention ':/univention/udm/users/user/?scope=two' Accept:application/json { "error": { "code": 422, "error": { "query_string": { "scope": "Value has to be one of [u'sub', u'one', u'base', u'base+one']" } }, "message": "1 error(s) occurred:\nQuery string \"scope\": Value has to be one of [u'sub', u'one', u'base', u'base+one']\n", "title": "Unprocessable Entity", "traceback": null } } We could improove this. Ideas: * use a HAL embedded object, e.g. "udm:error" instead of "error". * cleanup message? * each item in "error" should be described and errors in properties should be indented/nested so that the structure of looks like: { "code": 422, "title": "Unprocessable Entity", "traceback": null "_embedded": { "udm:error": [{ "properties": { "username": "The username is prohibited...", "uidNumber": "The uid is alread in use", }, # ? }, { "options": { "foo": "unknown option", } }] } } (just a draft, needs a little bit more thinking)
The error response format has been improved while being backwards compatible in the response format. Previously `response['error']['error']` contained a inconsistent sometimes nested dict structure. The new format contains a embedded HAL relation/object which allows multiple errors as list describing their location, e.g.: ``` "udm:error": [ { "location": [ "query", "position" ], "message": "Value is not a LDAP DN.", "type": "value_error" } ] ``` That format is also now also described by the OpenAPI schema. A new test case which tests various errors has been added. Some example requests to trigger errors: eval "$(ucr shell ldap/base)" curl -H 'Accept: application/json' "http://Administrator:univention@localhost/univention/udm/users/user/uid=Administrator,cn=users,$ldap_base" -X PUT -H 'Content-Type: application/json' -d '{"properties": {}}' | python -m json.tool curl -H 'Accept: application/json' 'http://Administrator:univention@localhost/univention/udm/users/user/?scope=blah&filter=foobar' | python -m json.tool curl -H 'Accept: application/json' "http://Administrator:univention@localhost/univention/udm/users/user/uid=Administrator,cn=users,$ldap_base" -X PATCH -H 'Content-Type: application/json' -d '{"properties": {"description": ["foo"], "lastname": []}}' | python -m json.tool curl -s -H 'Accept: application/json' "http://Administrator:univention@localhost/univention/udm/users/user/?position=cn=userz,$ldap_base" | python -m json.tool univention-directory-manager-rest.yaml 88ce48c30d80 | feat(udm-rest): enhance response error format using HAL univention-directory-manager-rest (10.0.4-9) a7fb5930d72e | feat(udm-rest-client): add error handling for 422 and 500 errors 041a8521a773 | refactor(udm-rest): use typing for argument sanitization univention-directory-manager-rest (10.0.4-10) 88ce48c30d80 | feat(udm-rest): enhance response error format using HAL ucs-test (10.0.7-29) 88ce48c30d80 | feat(udm-rest): enhance response error format using HAL
Verified: * code review * changelogs and YAML OK * compared differences of OpenAPI schema * successfully executing ucs-test/73_udm-rest * install of official package and checked completness
<https://errata.software-univention.de/#/?erratum=5.0x510>