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) =>
|
||||
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());
|
||||
}
|
||||
|
||||
+10
-3
@@ -5,14 +5,23 @@ using WebApi.Extensions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
|
||||
const string devCorsPolicy = "dev-cors";
|
||||
|
||||
builder.Services
|
||||
.AddApplicationServices(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();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseCors(devCorsPolicy);
|
||||
app.MapOpenApi();
|
||||
app.MapScalarApiReference();
|
||||
}
|
||||
@@ -25,6 +34,4 @@ app
|
||||
.MapTrackEndpoints()
|
||||
.MapUserEndpoints();
|
||||
|
||||
app.Run();
|
||||
|
||||
public partial class Program { }
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user