Skip to content

errorMessages should be passed as string #124

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

Open
buti1021 opened this issue Mar 21, 2023 · 3 comments
Open

errorMessages should be passed as string #124

buti1021 opened this issue Mar 21, 2023 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed

Comments

@buti1021
Copy link
Contributor

The error messages get translated into the details property of the problem details object. By the RFC standard this property is a string.
Currently a list of errormessages can be passed to the NotFound and Error Method, which then get concatenated.
e.g.,:

var details = new StringBuilder("Next error(s) occured:");
foreach (var error in result.Errors) details.Append("* ").Append(error).AppendLine();

This breaks internationalization, as the string at the start is english and already happens if only a single string is passed.
I think the best approach would be to allow only strings and make the developer responsible for concatenation.
What do you think?
@ardalis @KyleMcMaster

@ardalis ardalis added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers hacktoberfest labels Oct 3, 2023
@ardalis
Copy link
Owner

ardalis commented May 16, 2024

Related to #126.

We need a better story for managing strings and internationalization.

@LouisTrinczek
Copy link

LouisTrinczek commented Oct 9, 2024

I think there shouldn't be more than one error, per ProblemDetails instance.
Is there a common approach in dotnet, to returning a list of multiple ProblemDetails?

Because then the developer could work with a list of ProblemDetails, and concatenate the errors himself, and also translate it by himself how he sees fit using only the actual error message, he defined returned from the ProblemDetails.Detail field.

I am facing the internationalization error myself right now working with this package.

@ardalis
Copy link
Owner

ardalis commented Nov 1, 2024

Is there a common approach in dotnet, to returning a list of multiple ProblemDetails?

Not that I'm aware of but I don't claim to be an expert. I could imagine something like a validation problem in which several parts of a POSTed DTO were invalid and you wanted to be able to convert a Result.Invalid with its error list into a ProblemDetails (even though probably a BadRequest makes more sense...) and at that point you'd have several (validation) errors.

Or maybe you have some parallel tasks you fire off, and some fail, and you have an AggregateException and you want to be able to include all of the failures states and their respective error messages in the ProblemDetails (I don't think you'd return more than one ProblemDetails). Probably a rare consideration but perhaps one some need to support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants