Class Error
A coded error carried by LayerResponse. Code is the stable key clients read; Message is English for developers and logs. Text for users comes from LocalizedMessage, which the API edge fills in the request's language (IErrorLocalizer). Exception and AdditionalData are kept for logs only.
Implements
Inherited Members
Namespace: ZhEaIsNsAaBn.Utilities
Assembly: ZhEaIsNsAaBn.LayerResponse.dll
Syntax
[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "Error is the house name for the result error type (STYLE_GUIDE §6); C# consumers only.")]
public sealed record Error : IEquatable<Error>
Constructors
Error(string, string?, string, string, Severity?, Exception?, IReadOnlyDictionary<string, object>?)
Creates an error with an explicit Type.
Declaration
[JsonConstructor]
public Error(string code, string? type, string messageAr, string message, Severity? severity = null, Exception? exception = null, IReadOnlyDictionary<string, object>? additionalData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | code | Stable error code, usually from |
| string | type | Error category. Default: |
| string | messageAr | Arabic message for users. |
| string | message | English message for users. |
| Severity | severity | Severity. Default: Medium. |
| Exception | exception | The exception behind the error, if any. Never serialized. |
| IReadOnlyDictionary<string, object> | additionalData | Extra values for logs. Never serialized. Default: empty. |
Error(string, string, string, Severity?, Exception?, IReadOnlyDictionary<string, object>?)
Creates an error with the default Type (General).
Declaration
public Error(string code, string messageAr, string message, Severity? severity = null, Exception? exception = null, IReadOnlyDictionary<string, object>? additionalData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | code | Stable error code, usually from |
| string | messageAr | Arabic message for users. |
| string | message | English message for users. |
| Severity | severity | Severity. Default: Medium. |
| Exception | exception | The exception behind the error, if any. Never serialized. |
| IReadOnlyDictionary<string, object> | additionalData | Extra values for logs. Never serialized. Default: empty. |
Fields
None
The "no error" value used by successful responses.
Declaration
public static readonly Error None
Field Value
| Type | Description |
|---|---|
| Error |
Properties
AdditionalData
Extra values for logs. Never serialized. Empty when not set.
Declaration
[JsonIgnore]
public IReadOnlyDictionary<string, object> AdditionalData { get; init; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> |
Arguments
Values for the named placeholders in the message, e.g. Field → "Email". Serialized, so a client that translates
codes itself can fill them too — put only values that are safe to show the caller. null when not set.
Declaration
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public IReadOnlyDictionary<string, object?>? Arguments { get; init; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> |
Code
Stable error code, e.g. NotFound.
Declaration
public string Code { get; init; }
Property Value
| Type | Description |
|---|---|
| string |
Exception
The exception behind the error, for logs. Never serialized (STYLE_GUIDE §6).
Declaration
[JsonIgnore]
public Exception? Exception { get; init; }
Property Value
| Type | Description |
|---|---|
| Exception |
LocalizedMessage
The message for users in the request's language. Set by the API edge (IErrorLocalizer); null inside the application.
Declaration
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public LocalizedMessage? LocalizedMessage { get; init; }
Property Value
| Type | Description |
|---|---|
| LocalizedMessage |
Message
English message for developers and logs; also the last fallback for users. May hold named placeholders such as
{Field}, filled from Arguments.
Declaration
public string Message { get; init; }
Property Value
| Type | Description |
|---|---|
| string |
MessageAR
Arabic message. Transitional: ErrorLocalizer uses it as the ar text when no resource has one. It is
removed once every error catalog ships its own .resx files (before the first release).
Declaration
public string MessageAR { get; init; }
Property Value
| Type | Description |
|---|---|
| string |
Severity
How serious the error is.
Declaration
public Severity Severity { get; init; }
Property Value
| Type | Description |
|---|---|
| Severity |
Type
Error category. Default: General.
Declaration
public string Type { get; init; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
Deconstruct(out string, out string, out string, out Severity, out Exception?, out IReadOnlyDictionary<string, object>)
Splits the error into its parts.
Declaration
public void Deconstruct(out string code, out string messageAR, out string message, out Severity severity, out Exception? exception, out IReadOnlyDictionary<string, object> additionalData)
Parameters
| Type | Name | Description |
|---|---|---|
| string | code | Receives Code. |
| string | messageAR | Receives MessageAR. |
| string | message | Receives Message. |
| Severity | severity | Receives Severity. |
| Exception | exception | Receives Exception. |
| IReadOnlyDictionary<string, object> | additionalData | Receives AdditionalData. |
Unknown(Exception, IReadOnlyDictionary<string, object>?)
Creates the generic "unknown error" with fixed bilingual text, keeping the exception for logs.
Declaration
public static Error Unknown(Exception exception, IReadOnlyDictionary<string, object>? additionalData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Exception | exception | The exception that was caught. |
| IReadOnlyDictionary<string, object> | additionalData | Extra values for logs, if any. |
Returns
| Type | Description |
|---|---|
| Error | An error with code |