Skip to content

Commit

Permalink
Make sure we don't loose details when exception is thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang committed May 21, 2018
1 parent 60d0509 commit 58619e1
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/ProblemDetails/ProblemDetailsMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -118,22 +117,27 @@ private MvcProblemDetails GetDetails(HttpContext context, Exception error)

// We don't want to leak exception details unless it's configured,
// even if the user mapped the exception into ExceptionProblemDetails.
if (result is ExceptionProblemDetails ex && Options.IncludeExceptionDetails(context))
if (result is ExceptionProblemDetails ex)
{
try
{
var details = DetailsProvider.GetDetails(ex.Error);
return new DeveloperProblemDetails(ex, details);
}
catch (Exception e)
if (Options.IncludeExceptionDetails(context))
{
// Failed to get exception details for the specific exception.
// Fall back to generic status code problem details below.
Logger.ProblemDetailsMiddlewareException(e);
try
{
var details = DetailsProvider.GetDetails(ex.Error);
return new DeveloperProblemDetails(ex, details);
}
catch (Exception e)
{
// Failed to get exception details for the specific exception.
// Fall back to generic status code problem details below.
Logger.ProblemDetailsMiddlewareException(e);
}
}

return new StatusCodeProblemDetails(ex.Status ?? context.Response.StatusCode);
}

return new StatusCodeProblemDetails(result.Status ?? context.Response.StatusCode);
return result;
}

private MvcProblemDetails GetProblemDetails(Exception error)
Expand Down

0 comments on commit 58619e1

Please sign in to comment.