Skip to content

Instantly share code, notes, and snippets.

@bruceharrison1984
Last active August 30, 2019 15:39
Show Gist options
  • Save bruceharrison1984/2dd07d7f49ca913d2d5cac8d2159fc0f to your computer and use it in GitHub Desktop.
Save bruceharrison1984/2dd07d7f49ca913d2d5cac8d2159fc0f to your computer and use it in GitHub Desktop.
[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