Reputation:
For reference, I am referencing http://www.restapitutorial.com/httpstatuscodes.html while working on this.
I have a Web API 2.2 service that allows a user to add "print requests" with AddPrintRequest(...)
, then batch those requests using a call to BatchRequests(...)
.
The BatchRequests
method validates each request, and batches the valid ones. If there is at least one valid request, the batch is created and we return a HTTP 201 (Created). But what should we return if no batch is created? We don't consider this an error, but want to signal to the client why no batch was created. What is the correct status code?
Upvotes: 1
Views: 44
Reputation: 5312
You can use Conflict and then throw an exception with a message.
Equivalent to HTTP status 409. Conflict indicates that the request could not be carried out because of a conflict on the server.
var message = "your message here";
throw new HttpResponseException(
Request.CreateErrorResponse(HttpStatusCode.Conflict, message));
https://msdn.microsoft.com/en-us/library/system.net.httpstatuscode(v=vs.110).aspx
Upvotes: 0