コード例 #1
0
 def handle_error(self, e):
     if e.__class__ in self._error_handlers:
         handler = self._error_handlers[e.__class__]
         result = handler(e)
         e = HTTPException(str(e))
         e.data, e.code = result if len(result) == 2 else (result, 500)
     elif self._default_error_handler:
         result = self._default_error_handler(e)
         e = HTTPException(str(e))
         e.data, e.code = result if len(result) == 2 else (result, 500)
     return super(Api, self).handle_error(e)
コード例 #2
0
ファイル: api.py プロジェクト: alexa-infra/flask-restplus
 def handle_error(self, e):
     if e.__class__ in self._error_handlers:
         handler = self._error_handlers[e.__class__]
         result = handler(e)
         e = HTTPException(str(e))
         e.data, e.code = result if len(result) == 2 else (result, 500)
     return super(Api, self).handle_error(e)
コード例 #3
0
    def test_handle_error_401_sends_challege_default_realm(self, api):
        exception = HTTPException()
        exception.code = 401
        exception.data = {"foo": "bar"}

        resp = api.handle_error(exception)
        assert resp.status_code == 401
        assert resp.headers["WWW-Authenticate"] == 'Basic realm="flask-restx"'
コード例 #4
0
    def test_handle_error_401_sends_challege_default_realm(self, api):
        exception = HTTPException()
        exception.code = 401
        exception.data = {'foo': 'bar'}

        resp = api.handle_error(exception)
        assert resp.status_code == 401
        assert resp.headers['WWW-Authenticate'] == 'Basic realm="flask-restplus"'
コード例 #5
0
ファイル: test_api.py プロジェクト: NDevox/flask-restful
    def test_handle_error_401_sends_challege_default_realm(self):
        exception = HTTPException()
        exception.code = 401
        exception.data = {'foo': 'bar'}

        with self.app_401.test_request_context('/foo'):
            resp = self.api_401.handle_error(exception)
            self.assertEquals(resp.status_code, 401)
            self.assertEquals(resp.headers['WWW-Authenticate'],
                              'Basic realm="flask-restful"')
コード例 #6
0
    def test_handle_error_401_sends_challege_default_realm(self):
        api = restplus.Api(self.app, serve_challenge_on_401=True)
        exception = HTTPException()
        exception.code = 401
        exception.data = {'foo': 'bar'}

        with self.app.test_request_context('/foo'):
            resp = api.handle_error(exception)
            self.assertEqual(resp.status_code, 401)
            self.assertEqual(resp.headers['WWW-Authenticate'],
                             'Basic realm="flask-restful"')
コード例 #7
0
    def test_when_flask_restful_error_is_raised(self):
        expected_status_code = 400
        expected_message = ["Input Error - field: missing"]

        exception = HTTPException()
        exception.data = {'message': {'field': 'missing'}}
        exception.code = 400

        response = handle_error(exception)

        self.assertResponse(response, expected_status_code, expected_message)
コード例 #8
0
    def test_handle_error_401_sends_challege_default_realm(self):
        api = restplus.Api(self.app, serve_challenge_on_401=True)
        exception = HTTPException()
        exception.code = 401
        exception.data = {'foo': 'bar'}

        with self.app.test_request_context('/foo'):
            resp = api.handle_error(exception)
            self.assertEqual(resp.status_code, 401)
            self.assertEqual(resp.headers['WWW-Authenticate'],
                             'Basic realm="flask-restful"')
コード例 #9
0
ファイル: common_utils.py プロジェクト: satyanani40/cabx
def raise_exception(message, message_dict, error_code=http.UNPROCESSABLE_REQUEST.code):
    e = HTTPException(message)
    e.data = message_dict
    e.code = error_code
    raise e