Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created June 18, 2012 10:30
Show Gist options
  • Save JakeGinnivan/2947788 to your computer and use it in GitHub Desktop.
Save JakeGinnivan/2947788 to your computer and use it in GitHub Desktop.
public HttpResponseMessage Something()
{
if (someErrorCondition)
{
return new HttpResponseMessage<ErrorResponse>(new ErrorResponse("Blah error occured"), HttpStatusCode.500); // Whatever the code is
}
return new HttpResponseMessage<Result>(myResult);
}
public class ErrorResponse
{
public ErrorResponse()
{
}
public ErrorResponse(string error)
{
Error = error;
}
public string Error {get;set;}
}
//If client sends accept: application/xml they will get something like
<ErrorResponse>
<Error>my error text>
</ErrorResponse>
//If client sends accept: application/json they will get something like
{ "_error": "my error msg" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment