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

Using RFC as ProblemDetails type #47

Closed
daniel-white opened this issue Apr 23, 2020 · 6 comments
Closed

Using RFC as ProblemDetails type #47

daniel-white opened this issue Apr 23, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@daniel-white
Copy link

Would it make sense to have an option for the ProblemDetails Type Property use the HelpLink text from the defined Exceptions that have a reference to a HTTP status code in an RFC?

Meaning - why not map to these?

https://github.com/ofpinewood/http-exceptions/blob/master/src/Opw.HttpExceptions/ResponseStatusCodeLink.cs

@petervandenhout petervandenhout self-assigned this Apr 25, 2020
@petervandenhout
Copy link
Member

petervandenhout commented Apr 25, 2020

I think that would make sense.

I'll update the ProblemDetailsExceptionMapper to return the Exception.HelpLink or an URI with the Exception type name ("error:[Type:slug]").
And update the ProblemDetailsHttpResponseMapper to return a status code information link (https://tools.ietf.org/html/rfc7231) or the URI with the HTTP status name ("error:[status:slug]").

@petervandenhout
Copy link
Member

petervandenhout commented Apr 25, 2020

@daniel-white I've created a PR for the change, let me know if this work for you or if it needs something more.
#48

I'll merge the changes in when you agree or in a day or 2...

@daniel-white
Copy link
Author

@petervandenhout Yeah that’s what I was thinking. However it introduces a slight breaking change. Might be good to put it behind a setting flag.

@petervandenhout
Copy link
Member

petervandenhout commented Apr 25, 2020

@daniel-white
I've updated it to make using a help link for ProblemDetails type property configurable in the options.
When UseHelpLinkAsProblemDetailsType is set to true the mappers uses the Exception.HelpLink or the HTTP status code information link to map the ProblemDetails.Type property. And when you want to set a default link for your help pages, you can set DefaultHelpLink.

mvcBuilder.AddHttpExceptions(options =>
{
    options.UseHelpLinkAsProblemDetailsType = true;
    options.DefaultHelpLink = new Uri("http://www.example.com/help-page");
});

@daniel-white
Copy link
Author

@petervandenhout This is great. Thanks!

petervandenhout added a commit that referenced this issue Apr 26, 2020
* Using RFC as ProblemDetails type #47
@petervandenhout
Copy link
Member

The changes have been merged and a new release has been created (2.7). It will be available on nuget soon.

https://www.nuget.org/packages/Opw.HttpExceptions.AspNetCore/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants