Class ResourceException
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:
- ResourceNotFoundException - Resource not found (404)
- ConflictException - Resource conflict (409)
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
statusCodeintThe HTTP status code associated with the exception.
messagestringThe error message that explains the reason for the exception.
innerExceptionExceptionThe 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
messagestringThe 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
messagestringThe error message that explains the reason for the exception.
innerExceptionExceptionThe 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
resourcestringThe type or name of the resource associated with the error.
statusCodeint?The HTTP status code representing the error. Defaults to 404.
messagestringA custom error message. Defaults to a generic message using the resource name.
innerExceptionExceptionThe 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
ResourceId
Gets the identifier of the resource associated with this exception.
public string? ResourceId { get; protected init; }
Property Value
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
resourcestringThe type or name of the resource.
resourceIdstringThe 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
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
Returns
- ResourceException
The current exception instance for fluent configuration.