mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-26 03:51:14 +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:
@@ -6,6 +6,9 @@ namespace SatelliteProvider.Api;
|
||||
|
||||
public sealed class GlobalExceptionHandler : IExceptionHandler
|
||||
{
|
||||
private const string JsonFieldErrorMessage = "The field value is invalid.";
|
||||
private const string BadRequestDetailMessage = "The request could not be processed.";
|
||||
|
||||
private readonly ILogger<GlobalExceptionHandler> _logger;
|
||||
|
||||
public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger)
|
||||
@@ -89,7 +92,7 @@ public sealed class GlobalExceptionHandler : IExceptionHandler
|
||||
{
|
||||
Status = badRequest.StatusCode,
|
||||
Title = "Bad Request",
|
||||
Detail = badRequest.Message,
|
||||
Detail = BadRequestDetailMessage,
|
||||
};
|
||||
|
||||
await httpContext.Response.WriteAsJsonAsync(
|
||||
@@ -107,13 +110,10 @@ public sealed class GlobalExceptionHandler : IExceptionHandler
|
||||
if (current is JsonException jsonEx)
|
||||
{
|
||||
var path = NormalizeJsonPath(jsonEx.Path);
|
||||
var message = string.IsNullOrEmpty(jsonEx.Message)
|
||||
? "Invalid JSON."
|
||||
: jsonEx.Message;
|
||||
|
||||
return new Dictionary<string, string[]>
|
||||
{
|
||||
[path] = new[] { message }
|
||||
[path] = new[] { JsonFieldErrorMessage }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user