本文整理汇总了Python中rest_framework.response.Response.exception方法的典型用法代码示例。如果您正苦于以下问题:Python Response.exception方法的具体用法?Python Response.exception怎么用?Python Response.exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rest_framework.response.Response
的用法示例。
在下文中一共展示了Response.exception方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_exception
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import exception [as 别名]
def handle_exception(self, exc):
# REST API drops the string attached to Django's PermissionDenied
# exception, and replaces it with a generic "Permission Denied"
if isinstance(exc, DjangoPermissionDenied):
response=Response({'detail': {"error": "PermissionDenied", "specific_error": str(exc), "fields": {}}}, status=status.HTTP_403_FORBIDDEN)
response.exception=True
return response
else:
return super(XOSListCreateAPIView, self).handle_exception(exc)
示例2: handle_exception
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import exception [as 别名]
def handle_exception(self, request, exc):
if hasattr(exc, 'code') and exc.code == 503:
sys.stderr.write(traceback.format_exc())
event_id = capture_exception()
context = {
'detail': six.text_type(exc),
'errorId': event_id,
}
response = Response(context, status=503)
response.exception = True
return response
return super(IntegrationEndpoint, self).handle_exception(request, exc)
示例3: _failure_response
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import exception [as 别名]
def _failure_response(ident, response, data=None):
"""
Given an identifier, a response from a view and optional data, return a
Response object that describes the error.
"""
result = {"invalid_data_id": ident, "detail": response.data.get("detail", response.data)}
if data:
result["invalid_data"] = data
response = Response(result, status=response.status_code)
# This tells ChangesetMiddleware to abort the transaction.
response.exception = True
return response
示例4: handle_exception
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import exception [as 别名]
def handle_exception(self, request, exc):
try:
response = super(Endpoint, self).handle_exception(exc)
except Exception as exc:
import sys
import traceback
sys.stderr.write(traceback.format_exc())
event_id = capture_exception()
context = {
'detail': 'Internal Error',
'errorId': event_id,
}
response = Response(context, status=500)
response.exception = True
return response
示例5: handle_exception
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import exception [as 别名]
def handle_exception(self, exc):
"""
Handle any exception that occurs, by returning an appropriate response,
or re-raising the error.
"""
print "lalalalalala"
if isinstance(exc, (exceptions.NotAuthenticated,
exceptions.PermissionDenied,
exceptions.AuthenticationFailed)):
response = Response({"success": False, "error_code": 401,
"error_msg": "Not authorized"})
else:
response = Response({"success": False, "error_code": 500,
"error_msg": "Server Error"})
response.exception = True
return response
示例6: bulk_destroy
# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import exception [as 别名]
def bulk_destroy(self, request):
"""
This API call allows deleting repositories. It is an almost exact
mirror of `create` call. The same data must be fed into it.
__Method__: `DELETE`
__URL__: `/repos/`
__Data__:
{
"release_id": string,
"variant_uid": string,
"arch": string,
"service": string,
"repo_family": string,
"content_format": string,
"content_category": string,
"name": string,
"shadow": bool,
"product_id": <int|null>
}
It is possible to send a list of these objects so that multiple
repositories can be deleted at the same time atomically.
__Response__: Nothing
"""
data = request.data
in_bulk = True
if not isinstance(data, list):
data = [data]
in_bulk = False
for idx, input in enumerate(data):
input_id = (' in input %d' % idx) if in_bulk else ''
allowed_keys = set(['release_id', 'variant_uid', 'arch', 'service',
'repo_family', 'content_format', 'content_category',
'name', 'shadow', 'product_id'])
missing_keys = allowed_keys - set(input.keys())
additional_keys = set(input.keys()) - allowed_keys
if missing_keys:
resp = Response(status=status.HTTP_400_BAD_REQUEST,
data={'detail': 'Missing arguments: %s%s'
% (', '.join(missing_keys), input_id)})
resp.exception = True
return resp
if additional_keys:
resp = Response(status=status.HTTP_400_BAD_REQUEST,
data={'detail': 'Unknown data fields: %s%s'
% (', '.join(additional_keys), input_id)})
resp.exception = True
return resp
kwargs = {'variant_arch__arch__name': input['arch'],
'variant_arch__variant__variant_uid': input['variant_uid'],
'variant_arch__variant__release__release_id': input['release_id'],
'service__name': input['service'],
'repo_family__name': input['repo_family'],
'content_format__name': input['content_format'],
'content_category__name': input['content_category'],
'name': input['name'],
'shadow': hacks.convert_str_to_bool(input['shadow'], name='shadow'),
'product_id': (hacks.convert_str_to_int(input['product_id'], name='product_id')
if input['product_id'] is not None else None)}
obj = models.Repo.objects.get(**kwargs)
request.changeset.add('Repo', obj.pk, json.dumps(obj.export()), 'null')
obj.delete()
return Response(status=status.HTTP_204_NO_CONTENT)