namespace StellaOps.Microservice.Validation; /// /// Exception thrown when request or response body fails schema validation. /// public sealed class SchemaValidationException : Exception { /// /// Gets the endpoint path where validation failed. /// public string EndpointPath { get; } /// /// Gets the HTTP method of the endpoint. /// public string EndpointMethod { get; } /// /// Gets whether this was request or response validation. /// public SchemaDirection Direction { get; } /// /// Gets the list of validation errors. /// public IReadOnlyList Errors { get; } /// /// Creates a new schema validation exception. /// public SchemaValidationException( string endpointMethod, string endpointPath, SchemaDirection direction, IReadOnlyList errors) : base(BuildMessage(endpointMethod, endpointPath, direction, errors)) { EndpointMethod = endpointMethod; EndpointPath = endpointPath; Direction = direction; Errors = errors; } private static string BuildMessage( string method, string path, SchemaDirection direction, IReadOnlyList errors) { var directionText = direction == SchemaDirection.Request ? "request" : "response"; return $"Schema validation failed for {directionText} of {method} {path}: {errors.Count} error(s)"; } }