Last active
May 23, 2019 20:22
-
-
Save vmandic/9ba8f7ac0a62e0b6c7c8fc8aad2163c7 to your computer and use it in GitHub Desktop.
meds-processor, part/4, snippet #21
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
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