Last active
August 30, 2019 15:39
-
-
Save bruceharrison1984/2dd07d7f49ca913d2d5cac8d2159fc0f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[FunctionName("GetWidget")] | |
public async Task<IActionResult> GetWidget([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "/widgets/{id}")] HttpRequest req, int id, ILogger log) | |
{ | |
log.LogInformation($"getting widget: ${id}"); | |
try | |
{ | |
var selectedItem = await _dbContext.Widgets.FindAsync(id); | |
return new ObjectResult(selectedItem); | |
} | |
catch (Exception e) | |
{ | |
return new CustomObjectResult(e.Message, StatusCodes.Status500InternalServerError); | |
} | |
} | |
class CustomObjectResult : ObjectResult | |
{ | |
public CustomObjectResult(object data, int statusCode) : base(data) | |
{ | |
this.StatusCode = statusCode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment