Skip to content

Instantly share code, notes, and snippets.

@vmandic
Last active May 23, 2019 20:22
Show Gist options
  • Save vmandic/9ba8f7ac0a62e0b6c7c8fc8aad2163c7 to your computer and use it in GitHub Desktop.
Save vmandic/9ba8f7ac0a62e0b6c7c8fc8aad2163c7 to your computer and use it in GitHub Desktop.
meds-processor, part/4, snippet #21
using MedsProcessor.WebAPI.Infrastructure;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
namespace MedsProcessor.WebAPI.Controllers
{
[ApiVersionNeutral, Route("api/[controller]")]
public class ErrorController : ApiControllerBase
{
/// <summary>
/// Catches and handles global exceptions by intercepting HTTP errors specified through the URL.
/// </summary>
/// <returns>Returns a JSON formatted message which will contain exception details if the framework can resolve the latest error.</returns>
[HttpGet, Produces(typeof(ApiDataResponse<System.Exception>))]
public ActionResult<ApiHttpResponse> GetError()
{
var exFeat = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
return exFeat == null
? ApiResponse.ForMessage("Internal server error details unavailable.", 500)
: ApiResponse.ForData(exFeat.Error, 500, exFeat.Error.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment