示例#1
0
    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')
示例#2
0
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'})
示例#3
0
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'})
示例#4
0
    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')