Not-found lookups return null/false instead of throwing NotFoundException across all services — a missing row is expected control flow, not an exceptional condition. NotFoundException stays for embedded precondition checks inside mutations (missing parent, invalid foreign reference). Guard (copied from mic-check) enforces required arguments at the top of every service method. A ported IModelValidator<T> framework validates every request DTO at the API layer via a new ValidationEndpointFilter, returning a 400 with field-level messages; services re-run the same validator and throw for direct callers that bypass the API. Endpoints translate null/false into 404 via a new ToApiResult() helper. The agent toolset boundary translates the same nullable/bool results into the tool-error text the model already expected.
15 lines
482 B
C#
15 lines
482 B
C#
namespace Novelly.Api.Common.Validation;
|
|
|
|
public record ValidationError(string PropertyName, string Message);
|
|
|
|
public class ValidationResult
|
|
{
|
|
private readonly List<ValidationError> _errors = [];
|
|
|
|
public IReadOnlyList<ValidationError> Errors => _errors;
|
|
public bool IsValid => _errors.Count == 0;
|
|
public bool IsInvalid => _errors.Count > 0;
|
|
|
|
public void AddError(string propertyName, string message) => _errors.Add(new ValidationError(propertyName, message));
|
|
}
|