Flask teardown_request has to take an error