khellang / Middleware

Various ASP.NET Core middleware
MIT License
811 stars 112 forks source link

[Feature request] ProblemDetails middleware allow send Detail property out of the box in Production #194

Open janseris opened 1 year ago

janseris commented 1 year ago

The current middleware implementation allows to send in ProblemDetails: a) only Title (default option for Production)

Sometimes it is convenient for a client to know at least a bit of what happened, thus send Detail in the ProblemDetail in Production.

Suggested new option: c) Title and Detail for Production environment

Public API changes (new), no modification of the original public API is required (no breaking change):

ProblemDetailsOptions.MapToStatusCodeWithDetail<TException>(int statusCode)

as an alternative for the current API:

ProblemDetailsOptions.MapToStatusCode<TException>(int statusCode)

Example:

options.MapToStatusCodeWithDetail<ValidationException>(StatusCodes.Status422UnprocessableEntity);

Reference implementation which already contains this behavior: https://stackoverflow.com/a/74487747

luizen commented 1 year ago

Please!

PiotrKlimisz commented 1 year ago

+1 🙏 It would be great to have a separate options for a stackframes and the details property.