Skip to content

Ignore non-JSON error payload

Maciej Lenartowicz requested to merge reforis-125-ignore-non-json-errors into dev

Related https://gitlab.labs.nic.cz/turris/reforis/reforis/issues/125

The problem is that I can't find a way to register error handler only for some set of routes (except for manually registering it with decorator, but then we need to register it for every route manually). It can't be done on blueprint basis since it's overridden - " Another special case is the 500 internal server error which is always looked up from the application." - see https://flask.palletsprojects.com/en/1.1.x/api/#flask.Blueprint.errorhandler

Therefore I think we can filter out non-JSON errors on front-end, which will allow us to display a meaningful API error (JSON one) or display generic error message (any other case).

Example usage is an error from OpenVPN plugin - a conflict of client names. I believe having non-unique client names could end up in user's confusion and it should be blocked (resulting in CONFLICT status upon duplicate client POST).

Edited by Maciej Lenartowicz

Merge request reports