Browse Source

More tests

pull/349/head
Sebastian 7 years ago
parent
commit
4de7ed2e39
  1. 18
      src/Squidex.Web/ApiExceptionFilterAttribute.cs

18
src/Squidex.Web/ApiExceptionFilterAttribute.cs

@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
@ -60,7 +61,7 @@ namespace Squidex.Web
private static IActionResult OnValidationException(ValidationException ex)
{
return ErrorResult(400, new ErrorDto { Message = ex.Summary, Details = ex.Errors?.ToArray(e => e.Message) });
return ErrorResult(400, new ErrorDto { Message = ex.Summary, Details = ToDetails(ex) });
}
private static IActionResult ErrorResult(int statusCode, ErrorDto error)
@ -89,5 +90,20 @@ namespace Squidex.Web
context.Result = result;
}
}
private static string[] ToDetails(ValidationException ex)
{
return ex.Errors?.ToArray(e =>
{
if (e.PropertyNames?.Any() == true)
{
return $"{string.Join(", ", e.PropertyNames)}: {e.Message}";
}
else
{
return e.Message;
}
});
}
}
}

Loading…
Cancel
Save