You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, I'm under the impression that ProblemDetails are only returned in a response when there is no 'body' in the response. aka. No returned Object/Model.
Will ProblemDetails be updated to work with object/models?
For example, this code
✅ Response StatusCode == 400
❌ Payload is json representation of the model, not a `ProblemDetails.
using Microsoft.AspNetCore.Mvc.ModelBinding;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddProblemDetails();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseExceptionHandler();
app.UseStatusCodePages();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app
.MapGet("/badrequest", () =>
{
var errors = new ModelStateDictionary();
errors.AddModelError("username", "Not provided");
errors.AddModelError("age", "too old");
return TypedResults.BadRequest(errors);
})
.WithName("BadRequest")
.WithOpenApi();
app.Run();
and to test this with an .http file:
@host=https://localhost:7062/
GET {{host}}badrequest
Accept: application/json
Content-Type: application/json
The result is:
So is there any plans to help with this?
Or at least to allow a developer to say "Hi ProblemDetails code. If an object Foois provided as a response body .. then instead of returning aStatusCoderesponse, actually do aProblemDetailsresponse AND this method I'm giving you, is how we will handle that custom Foo object."
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
👋🏻 G'Day!
Currently, I'm under the impression that
ProblemDetails
are only returned in a response when there is no 'body' in the response. aka. No returned Object/Model.Will
ProblemDetails
be updated to work with object/models?For example, this code
and to test this with an
.http
file:The result is:
So is there any plans to help with this?
Or at least to allow a developer to say "Hi
ProblemDetails code. If an object
Foois provided as a response body .. then instead of returning a
StatusCoderesponse, actually do a
ProblemDetailsresponse AND this method I'm giving you, is how we will handle that customFoo
object."Beta Was this translation helpful? Give feedback.
All reactions