Skip to content

Commit

Permalink
Allows descriptors to raise Conflict error.
Browse files Browse the repository at this point in the history
Conflict (HTTP RESPONSE 409) indicates that there is a user-resolvable
problem with the state of the addressed resource.  For Axilent, we're
going to use Conflict to indicate a mis-configured content policy.
  • Loading branch information
LorenDavie committed Mar 21, 2012
1 parent b87bfa0 commit a0d9909
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions sharrock/descriptors.py
Expand Up @@ -452,3 +452,12 @@ def status_code(self,request):
"""
return Resource.response_codes[request.method.lower()]

# =======================
# = Miscellaneous Erros =
# =======================

class Conflict(Exception):
"""
An exception indicating there is a user-resolvable problem with the function or resource being addressed.
Should contain enough information so that the user can resolve the problem.
"""
6 changes: 5 additions & 1 deletion sharrock/views.py
Expand Up @@ -2,7 +2,7 @@
View functions for Sharrock.
"""
from sharrock import registry
from sharrock.descriptors import ParamRequired, MethodNotAllowed, AccessDenied
from sharrock.descriptors import ParamRequired, MethodNotAllowed, AccessDenied, Conflict
from django.shortcuts import render_to_response
from django.http import Http404, HttpResponse
import traceback
Expand Down Expand Up @@ -62,6 +62,8 @@ def execute_service(request,app,version,service_name,extension='json'):
return HttpResponse(str(ad),status=403)
except ParamRequired as pr:
return HttpResponse(str(pr),status=400) # missing parameter
except Conflict as con:
return HttpResponse(str(con),status=409) # something user-resolvable is wrong with the function

def execute_resource(request,app,version,resource_name,extension='json',model_id=None):
"""
Expand All @@ -85,6 +87,8 @@ def execute_resource(request,app,version,resource_name,extension='json',model_id
return HttpResponse(str(pr),status=400) # there is a missing required parameter
except MethodNotAllowed as mna:
return HttpResponse(str(mna),status=405) # the employed http method is not supported
except Conflict as con:
return HttpResponse(str(cont),status=409) # something user-resolvable is wrong with the resource
except Exception as e:
traceback.print_exc()
raise e
Expand Down

0 comments on commit a0d9909

Please sign in to comment.