Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception property to the problem details context #47651

Closed
bjornen77 opened this issue Apr 11, 2023 · 5 comments · Fixed by #47760
Closed

Add exception property to the problem details context #47651

bjornen77 opened this issue Apr 11, 2023 · 5 comments · Fixed by #47760
Labels
api-approved API was approved in API review, it can be implemented area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks feature-problem-details

Comments

@bjornen77
Copy link
Contributor

bjornen77 commented Apr 11, 2023

Background and Motivation

If an application is configured to generate problem details it would be good, if an exception occurs in the application, that the original exception can be retreived directly on the problem details context. The exception information can be used to customize the problem details when using the CustomizeProblemDetails functionality. The original exception can already be retreived using the IExceptionHandlerFeature, but having the exception directly on the context will be easier and more straight forward to use.

The exception property should be set when the problem details context is written from the built-in exception handler middlewares.

Proposed API

namespace Microsoft.AspNetCore.Http;

public class ProblemDetailsContext
{
+   public Exception? Exception { get; init; }
}

Usage Examples

builder.Services.AddProblemDetails(configure =>
    configure.CustomizeProblemDetails = (context) =>
    {
        if (context.Exception is not null)
        {
            // Customize problem details with information from exception.
        }
    }
);

Alternative Designs

N/A

Risks

None that I am aware of.

@bjornen77 bjornen77 added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Apr 11, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Apr 11, 2023
@bjornen77
Copy link
Contributor Author

#47554 (review)

@captainsafia @JamesNK

@captainsafia captainsafia added area-web-frameworks api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Apr 11, 2023
@ghost
Copy link

ghost commented Apr 11, 2023

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@captainsafia
Copy link
Member

captainsafia commented Apr 11, 2023

Thanks! This will go through API review before implementation.

@brunolins16 Do you have any insights that might guide the implementation/API review?

@BrennanConroy
Copy link
Member

API Review Notes:

  • Who is setting the exception?
    • We would be in DeveloperException page etc.
  • The Exception won't be written by our implementations of IProblemDetailsWriter
    • Would be up to the user to put the exception in Extensions in CustomizeProblemDetails if they want that

API Approved!

namespace Microsoft.AspNetCore.Http;

public sealed class ProblemDetailsContext
{
+   public Exception? Exception { get; init; }
}

@BrennanConroy BrennanConroy added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Apr 13, 2023
@brunolins16
Copy link
Member

Thanks! This will go through API review before implementation.

@brunolins16 Do you have any insights that might guide the implementation/API review?

Sorry for late response.I like the idea and I am glad that the api is already approved. This will also useful for IProblemDetailsWrtier implementation.

bjornen77 added a commit to bjornen77/aspnetcore that referenced this issue Apr 18, 2023
captainsafia pushed a commit that referenced this issue Apr 19, 2023
* add exception property to the problem details context

fixes: #47651

* set exception in middlewares

* add tests

* Update src/Middleware/Diagnostics/src/DeveloperExceptionPage/DeveloperExceptionPageMiddlewareImpl.cs

Co-authored-by: Chris Ross <Tratcher@Outlook.com>

---------

Co-authored-by: Chris Ross <Tratcher@Outlook.com>
@ghost ghost locked as resolved and limited conversation to collaborators May 25, 2023
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-web-frameworks feature-problem-details
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants
@captainsafia @BrennanConroy @amcasey @brunolins16 @bjornen77 and others