-
Notifications
You must be signed in to change notification settings - Fork 1
Setup ExceptionHandling
Harald Sømnes Hanssen edited this page Jun 3, 2019
·
4 revisions
Easiest way to the goal is to add the following code and possibly modify it.
app.UseExceptionHandler(a => a.Run(async context =>
{
var feature = context.Features.Get<IExceptionHandlerPathFeature>();
if (feature?.Error != null)
{
var exception = feature.Error;
var operationOutcome = ErrorHandlingMiddleware.GetOperationOutCome(exception, true);
var fhirJsonConverter = new FhirJsonSerializer();
var result = fhirJsonConverter.SerializeToString(operationOutcome);
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(result);
}
}));