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

Added ProblemDetailsException constructors #78

Merged
merged 5 commits into from
Jan 25, 2020
Merged

Added ProblemDetailsException constructors #78

merged 5 commits into from
Jan 25, 2020

Conversation

JonasSamuelsson
Copy link
Contributor

this set of constructors makes to code for throwing exceptions that translates into a status code response a little more terse and easier to read/write

for example:

throw new ProblemDetailsException(HttpStatusCode.BadRequest, "Invalid data");

vs

throw new ProblemDetailsException(new StatusCodeProblemDetails(HttpStatusCode.BadRequest) { Title = "Invalid data" });

would you be willing to accept this?

@khellang
Copy link
Owner

Sure, but I'm not sure the System.Net.HttpStatusCode enum is necessary. Using Microsoft.AspNetCore.Http.StatusCodes should be enough.

@JonasSamuelsson
Copy link
Contributor Author

I think that from a usability perspective the enum version really helps, just type new pde, Enter, ctrl+space and intellisense kicks in with a list of valid values. Microsoft.AspNetCore.Http.StatusCodes isn't all that discoverable.

Willing to reconsider? otherwise I'll go ahead and update the pr

@khellang
Copy link
Owner

khellang commented Jan 14, 2020

I think that from a usability perspective the enum version really helps

Yes and no. Fundamentally, HTTP status codes isn't a closed set, so using enums is kinda problematic. (Yes, I know .NET enums aren't technically closed sets, but I don't consider (HttpStatusCode)422 good usability)

I'd like to keep the code based aligned with what ASP.NET Core is doing, and they're using int.

I've pushed for using alternatives many many times, starting around 4-5 years ago (see aspnet/HttpAbstractions#345 (comment)), but I'm afraid that ship has sailed.

@JonasSamuelsson
Copy link
Contributor Author

I agree with you that an enum might be problematic, that's why I also added overloads taking an int.
But I'll go ahead and remove the enum contructors if that is how you want it.

esed a temporary editorconfig file, the real one will be merged from master
@JonasSamuelsson
Copy link
Contributor Author

Are you expecting anything else from me on this one?

@khellang khellang changed the title added ProblemDetailsException constructors Added ProblemDetailsException constructors Jan 25, 2020
@khellang khellang merged commit 024c508 into khellang:master Jan 25, 2020
@khellang
Copy link
Owner

Are you expecting anything else from me on this one?

Nope. Thanks for the contribution! ❤️

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

Successfully merging this pull request may close these issues.

None yet

2 participants