mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-26 15:11:15 +00:00
Sanitize 400 error messages in GlobalExceptionHandler and validation filters to use static strings. This change improves consistency and prevents leaking internal exception details. Updated tests to reflect new error messages for JSON parsing and bad request scenarios.
This commit is contained in:
@@ -31,6 +31,7 @@ public sealed class UavUploadValidationFilter : IEndpointFilter
|
||||
private const string MetadataKeyPrefix = "metadata.";
|
||||
private const string MetadataField = "metadata";
|
||||
private const string FilesField = "files";
|
||||
private const string MetadataJsonParseError = "`metadata` could not be parsed as JSON.";
|
||||
|
||||
private readonly IValidator<UavTileBatchMetadataPayload> _validator;
|
||||
private readonly JsonSerializerOptions _jsonOptions;
|
||||
@@ -72,14 +73,11 @@ public sealed class UavUploadValidationFilter : IEndpointFilter
|
||||
{
|
||||
payload = JsonSerializer.Deserialize<UavTileBatchMetadataPayload>(metadataField, _jsonOptions);
|
||||
}
|
||||
catch (JsonException ex)
|
||||
catch (JsonException)
|
||||
{
|
||||
// System.Text.Json with UnmappedMemberHandling.Disallow + [JsonRequired]
|
||||
// covers: unknown root/nested fields, missing required fields, type
|
||||
// mismatches. Surface uniformly as `errors.metadata`.
|
||||
return Results.ValidationProblem(new Dictionary<string, string[]>
|
||||
{
|
||||
[MetadataField] = new[] { $"`metadata` could not be parsed as JSON: {ex.Message}" },
|
||||
[MetadataField] = new[] { MetadataJsonParseError },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user