Beispiel #1
0
        def wrapper(*args, **kwargs):
            resp = f(*args, **kwargs)

            if isinstance(resp, tuple):
                data, code, headers = unpack(resp)
                return marshal({self.data_section_name: data}, data_wrapper), code, headers
            else:
                return marshal({self.data_section_name: resp}, data_wrapper)
Beispiel #2
0
 def wrapper(*args, **kwargs):
     resp = f(*args, **kwargs)
     parsed = self._parse_request_overrides()
     marshall_data = self.marshall_dict(*parsed)
     if isinstance(resp, tuple):
         data, code, headers = unpack(resp)
         return marshal(data, marshall_data), code, headers
     else:
         return marshal(resp, marshall_data)
            def inner_wrapper(*args, **kwargs):
                response = ApiResponse(status=code, message='', data=[], errors=[], code=None)

                resp = f(*args, **kwargs)
                # для обратной совместимости
                if isinstance(resp, tuple):
                    resp, response['code'], headers = unpack(resp)

                # предпочитаемый формат
                if isinstance(resp, ApiResponse):
                    response.update(resp)
                # если все значения по умолчанию и передаём только данные
                else:
                    response['data'] = resp

                response['data'] = restful.marshal(response['data'], fields)

                return response
Beispiel #4
0
    def wrapper(*args, **kwargs):
        request.json_param = get_json_param()
        e = None
        try:
            resp = resource(*args, **kwargs)
        except APIException as e:
            resp = e
        except KeyError as e:
            resp = APIException(SystemErrorCode.ArgumentError, u'参数错误',
                                request.path)
        except ValueError as e:
            resp = APIException(SystemErrorCode.ArgumentError, u'参数错误',
                                request.path)
        except MultipleResultsFound as e:
            resp = APIException(SystemErrorCode.DataError, u'数据不唯一',
                                request.path)
        except NoResultFound as e:
            resp = APIException(SystemErrorCode.DataError, u'数据不存在',
                                request.path)
        except Exception as e:
            resp = APIException(SystemErrorCode.UnkonwnError, u'未知错误',
                                request.path)

        if isinstance(resp, Response):  # There may be a better way to test
            return resp
        if isinstance(resp, APIException):
            print((resp.to_str()))
            if (e is not None):
                print get_error_log_str()
        data, code, headers = unpack(resp)
        from Main import api
        resp = api.make_response(data, code, headers=headers)
        if 'jsonpCallback' in request.values:
            jsonpCallback = request.values['jsonpCallback']
            resp.data = str(jsonpCallback) + '(' + resp.data + ');'
        try:
            request.session.close()  # 关闭Session
        except AttributeError:
            pass
        return resp