Class ValueObjectErrors
Namespace: AdCodicem.ValueObjects
Assembly: AdCodicem.ValueObjects.Abstractions.dll
Carries the code of a violated rule across an exception that a serializer, a data access library or any other integration throws in its own terms.
public static class ValueObjectErrors
Inheritance
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
An integration on a boundary reports a rejected value with the exception its ecosystem expects: a
JsonSerializationException for Newtonsoft.Json, a
DataException for Dapper. Those types have no place for a code, so the integrations store it in
An exception a value object's rule raised carries the code and the value object type, never the value it refused.
A DataAnnotations Validator methods raise for a refusal of UseValueObjectCheckErrors() adds the code of the constraint's rule, carries no type, and keeps
the message its provider wrote, which may hold the row.
Fields
ErrorCodeKey
The key under which an integration stores the code of the violated rule in
public const string ErrorCodeKey = "AdCodicem.ValueObjects.ErrorCode"
Field Value
Remarks
An integration of your own stores a code there the same way, so that exception.Data[ValueObjectErrors.ErrorCodeKey] = code.
Methods
TryGetCode(Exception, out string?)
Reads the code of the rule an exception, or one of the exceptions it wraps, carries.
public static bool TryGetCode(Exception exception, out string? code)
Parameters
exception Exception
The exception, as it was caught.
code string?
The code, or null when no exception of the chain carries one.
Returns
true when a code was found.
Remarks
Each exception is read in turn, from exception down its
BadHttpRequestException around the
SaveChanges with a
DbUpdateException around the Validator.ValidateObject, ValidateProperty and ValidateValue raise for a refusal of
An exception that reports no broken rule carries none. The error of a database provider for a row a CHECK
constraint from the rules refused carries one under the Entity Framework Core package's
UseValueObjectCheckErrors(), though no value object raised it, and a code of your own travels as the
framework's do.
Exceptions
exception is null.