code: def json_exception(context, request):
      
      request.response.status = context.code
      return {'error': context._status, 'messages': context.message}
docs: Always return json content in the body of Exceptions to xhr requests.