Table of Contents

Class ResourceException

Namespace
Excalibur.Data
Assembly
Excalibur.Data.Abstractions.dll

Base exception class for resource-related errors in the Excalibur framework.

public class ResourceException : ApiException, ISerializable
Inheritance
ResourceException
Implements
Derived
Inherited Members

Remarks

This exception serves as the base class for all resource-related errors, including:

Extends ApiException to preserve HTTP status code mapping and RFC 7807 problem details support.

Constructors

ResourceException()

Initializes a new instance of the ResourceException class.

public ResourceException()

ResourceException(int, string, Exception?)

Initializes a new instance of the ResourceException class with a status code, message, and inner exception.

protected ResourceException(int statusCode, string message, Exception? innerException)

Parameters

statusCode int

The HTTP status code associated with the exception.

message string

The error message that explains the reason for the exception.

innerException Exception

The exception that is the cause of the current exception.

ResourceException(string)

Initializes a new instance of the ResourceException class with a specified error message.

public ResourceException(string message)

Parameters

message string

The error message that explains the reason for the exception.

ResourceException(string, Exception?)

Initializes a new instance of the ResourceException class with a message and inner exception.

public ResourceException(string message, Exception? innerException)

Parameters

message string

The error message that explains the reason for the exception.

innerException Exception

The exception that is the cause of the current exception.

ResourceException(string, int?, string?, Exception?)

Initializes a new instance of the ResourceException class with resource information.

public ResourceException(string resource, int? statusCode = null, string? message = null, Exception? innerException = null)

Parameters

resource string

The type or name of the resource associated with the error.

statusCode int?

The HTTP status code representing the error. Defaults to 404.

message string

A custom error message. Defaults to a generic message using the resource name.

innerException Exception

The inner exception that caused this exception, if applicable.

Properties

Context

Gets additional contextual data related to the exception.

public Dictionary<string, object?> Context { get; }

Property Value

Dictionary<string, object>

A dictionary of context key-value pairs.

Resource

Gets the type or name of the resource associated with this exception.

public string? Resource { get; protected set; }

Property Value

string

The resource type or name, or null if not specified.

ResourceId

Gets the identifier of the resource associated with this exception.

public string? ResourceId { get; protected init; }

Property Value

string

The resource identifier, or null if not specified.

Methods

ForResource(string, string?)

Creates a new instance of the ResourceException class with resource information.

public static ResourceException ForResource(string resource, string? resourceId = null)

Parameters

resource string

The type or name of the resource.

resourceId string

The optional identifier of the resource.

Returns

ResourceException

A new ResourceException instance.

FormatMessage(string, string?)

Formats the default error message for a resource error.

protected static string FormatMessage(string resource, string? resourceId)

Parameters

resource string

The resource type.

resourceId string

The optional resource identifier.

Returns

string

A formatted error message.

GetProblemDetailsExtensions()

Gets additional extension data to include in problem details.

protected override IDictionary<string, object?>? GetProblemDetailsExtensions()

Returns

IDictionary<string, object>

A dictionary of extension data to include in the problem details response, or null if no extensions should be added.

Remarks

Derived types can override this method to add type-specific data to the problem details response. For example, a ValidationException might include a dictionary of field-level validation errors.

The returned dictionary keys will be added to the problem details Extensions collection.

WithContext(string, object?)

Adds contextual information to the exception.

public ResourceException WithContext(string key, object? value)

Parameters

key string

The context key.

value object

The context value.

Returns

ResourceException

The current exception instance for fluent configuration.