How do I control the HTTP Status Code in the protoRPC
response?
Let's say I have the following service:
class ApiService(remote.Service):
@remote.method(ApiRequestContextCreate, ApiResponseContextCreate)
def context_create(self, request):
cid = helpers.create_context(request.name)
return ApiResponseContextCreate(cid=cid)
Looks to me that the protoRPC API is lacking semantics: either the request can be fulfilled and returns a 200
or an exception is raised yielding to a 404
. Of course of could craft an error response in the RPC method but that seems kludgy.
Update: I have found I can raise ApplicationError
too for a 400
.
The HTTP status code is not part of the specification for ProtoRPC because ProtoRPC is meant to support protocols besides HTTP. It therefore cannot have specific-to-HTTP return codes. Instead, errors are returns by raising ApplicationError, using the error_name field to specify application specific error conditions.