Created
June 18, 2012 10:30
-
-
Save JakeGinnivan/2947788 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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