Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

c# return error status code based on exception

public IHttpActionResult GetUser(int userId, DateTime lastModifiedAtClient)
{
    var user = new DataEntities().Users.First(p => p.Id == userId);
    if (user.LastModified <= lastModifiedAtClient)
    {
        return StatusCode(HttpStatusCode.NotModified);
    }
    return Ok(user);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #return #error #status #code #based #exception
ADD COMMENT
Topic
Name
4+3 =