def test_error_handler(self): """Test the error_handler function.""" with backend.app.test_request_context(): resp = response.error_handler(Exception('error test'), debug=False) self.assertEqual( json.loads(resp.data), {"message": "server error"}) resp = response.error_handler( Exception('error test'), debug=False, payload={'a': 'b'}) self.assertEqual(json.loads(resp.data), { "message": "server error", "a": "b"}) resp = response.error_handler(Exception('error test'), debug=True) self.assertEqual( json.loads(resp.data)['message'], 'error test')
def other_error(error): """Catch any other exception. NOTE: This must be the last declared errorhandler or else it will swallow up other errorhandlers. """ return response.error_handler(error, payload={'type': 'general error'})
def test_error_handler(self): """Test the error_handler function.""" with backend.app.test_request_context(): resp = response.error_handler(Exception('error test'), debug=False) self.assertEqual(json.loads(resp.data), {"message": "server error"}) resp = response.error_handler(Exception('error test'), debug=False, payload={'a': 'b'}) self.assertEqual(json.loads(resp.data), { "message": "server error", "a": "b" }) resp = response.error_handler(Exception('error test'), debug=True) self.assertEqual(json.loads(resp.data)['message'], 'error test')