Return 400 for validation errors without identifier and enable permissive CORS in Development
This commit is contained in:
@@ -31,6 +31,6 @@ public static class ResultHttpExtensions
|
|||||||
|
|
||||||
private static Dictionary<string, string[]> ToValidationDictionary(IEnumerable<ValidationError> errors) =>
|
private static Dictionary<string, string[]> ToValidationDictionary(IEnumerable<ValidationError> errors) =>
|
||||||
errors
|
errors
|
||||||
.GroupBy(e => e.Identifier)
|
.GroupBy(e => string.IsNullOrEmpty(e.Identifier) ? "general" : e.Identifier)
|
||||||
.ToDictionary(g => g.Key, g => g.Select(e => e.ErrorMessage).ToArray());
|
.ToDictionary(g => g.Key, g => g.Select(e => e.ErrorMessage).ToArray());
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -5,14 +5,23 @@ using WebApi.Extensions;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder();
|
var builder = WebApplication.CreateBuilder();
|
||||||
|
|
||||||
|
const string devCorsPolicy = "dev-cors";
|
||||||
|
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddApplicationServices(builder.Configuration)
|
.AddApplicationServices(builder.Configuration)
|
||||||
.AddObservability(builder.Configuration);
|
.AddObservability(builder.Configuration);
|
||||||
|
|
||||||
|
if (builder.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
builder.Services.AddCors(options => options.AddPolicy(devCorsPolicy, policy =>
|
||||||
|
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
|
||||||
|
}
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
app.UseCors(devCorsPolicy);
|
||||||
app.MapOpenApi();
|
app.MapOpenApi();
|
||||||
app.MapScalarApiReference();
|
app.MapScalarApiReference();
|
||||||
}
|
}
|
||||||
@@ -25,6 +34,4 @@ app
|
|||||||
.MapTrackEndpoints()
|
.MapTrackEndpoints()
|
||||||
.MapUserEndpoints();
|
.MapUserEndpoints();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
public partial class Program { }
|
|
||||||
Reference in New Issue
Block a user