Feedback on ASP.NET Web API

Allow customize the formatting of error messages created with Request.CreateErrorResponse()

Currently Web Api returns error messages, which look like this:

{
"message": "Your request is invalid.",
"modelState":
{
"user.UserName": ["The UserName field is required."]
}
}

The parameter prefixes ("user." in this case) makes it more cumbersome to consume on the client side. Field names in the error message should match exactly field names in the original request. Also "modelState" doesn't make much sense here because there is just a list of error messages, nothing more. By default, this response should look like this instead:

{
"message": "Your request is invalid.",
"errors":
{
"userName": ["The UserName field is required."]
}
}

Or, at least provide an extension point to customize these error messages.

4 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Konstantin Tarkus shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
completed  ·  Daniel Roth responded  · 

The CreateErrorResponse extension method is just a simple convenience method that provides a default formatting for sending back error information (based on the HttpError class). You can provide whatever error format you’d like by constructing your own HttpResponseMessage or IHttpActionResult.

0 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...

Feedback and Knowledge Base