def deserialize(self, data, instance=None): partial = bool(instance) unmarshal_result = self.context['schema_class'](partial=partial).load( data, instance=instance) if unmarshal_result.errors: raise APIError(400, extra=unmarshal_result.errors) return unmarshal_result.data
def check_permission(self, instance=None): if self.get_instance_from_context( 'framework').get_request_method() not in self.SAFE_METHODS: raise APIError(403)
def check_permission(self, instance=None): if self.context['current_user'] is None: raise APIError(401)
def handled_exception(self): raise APIError(499, {'detail': 'Now this is a weird HTTP code'})
def get_object(self, queryset, pk): try: return queryset.get(pk=pk) except ObjectDoesNotExist: raise APIError(404)
def get_object(self, queryset, pk): try: return queryset.filter(id=pk).get() except DoesNotExist: raise APIError(404)
def get_object(self, queryset, pk): try: return queryset.filter_by(id=pk).one() except NoResultFound: raise APIError(404)