Table of Contents

Class DomainError

Namespace
FoundationaLLM.Common.Models.Services
Assembly
FoundationaLLM.Common.dll

Represents a domain-specific error (RFC 7807 style).

public class DomainError
Inheritance
DomainError
Inherited Members
Extension Methods

Properties

Detail

Gets or sets a specific, contextual explanation.

[JsonPropertyName("detail")]
public string? Detail { get; init; }

Property Value

string

Extensions

Gets or sets extra data – like ProblemDetails.Extensions.

[JsonPropertyName("extensions")]
public IReadOnlyDictionary<string, object?> Extensions { get; init; }

Property Value

IReadOnlyDictionary<string, object>

Instance

Gets or sets an optional detail about where did the error happen (operation name, aggregate id, etc.).

[JsonPropertyName("instance")]
public string? Instance { get; init; }

Property Value

string

Status

Gets the status code associated with the response or operation.

[JsonPropertyName("status")]
public int? Status { get; init; }

Property Value

int?

Title

Gets a short, human-readable title of the error.

[JsonPropertyName("title")]
public string Title { get; init; }

Property Value

string

Type

Gets a stable, machine-readable error type (like "file.rejected").

[JsonPropertyName("type")]
public string Type { get; init; }

Property Value

string

Methods

FromErrorMessage(string, int, string?)

Creates a new instance of the DomainError class using the specified error message as the detail.

public static DomainError FromErrorMessage(string errorMessage, int status = 500, string? instance = null)

Parameters

errorMessage string

The error message that describes the domain error. Cannot be null.

status int

The status code associated with the error message.

instance string

An optional instance detail about where the error occurred.

Returns

DomainError

A DomainError instance with the specified error message set as the detail.

FromException(Exception, int, string?)

Creates a new DomainError instance that represents the specified exception.

public static DomainError FromException(Exception ex, int status = 500, string? instance = null)

Parameters

ex Exception

The exception to convert into a DomainError. Cannot be null.

status int

The status code associated with the exception.

instance string

An optional instance detail about where the exception occurred.

Returns

DomainError

A DomainError instance containing information from the specified exception.

FromHttpResponse(HttpResponseMessage)

Creates a new instance of the DomainError class by parsing the specified HTTP response for problem details.

public static Task<DomainError> FromHttpResponse(HttpResponseMessage response)

Parameters

response HttpResponseMessage

The HTTP response message to extract problem details from. Must not be null.

Returns

Task<DomainError>

A DomainError instance populated with information from the response's problem details, or with default values if the response does not contain valid problem details.

Remarks

If the response content cannot be deserialized as ProblemDetails, default error information is used. This method does not throw on deserialization errors.

ToProblemDetails()

Converts the current instance to a new ProblemDetails object with equivalent values.

public ProblemDetails ToProblemDetails()

Returns

ProblemDetails

A ProblemDetails instance containing the type, title, detail, instance, and extensions from the current object.