Class ForbiddenError
Represents an authorization error (HTTP 403 equivalent). Use when the caller is authenticated but lacks permission.
public class ForbiddenError : Reason<ForbiddenError>, IReasonMetadata, IError, IReason, IErrorFactory<ForbiddenError>
- Inheritance
-
ForbiddenError
- Implements
- Inherited Members
- Extension Methods
Examples
Result<User>.Fail(new ForbiddenError());
Result<User>.Fail(new ForbiddenError("Admin role required"));
Result<User>.Fail(ForbiddenError.For("Delete", "Order"));
Constructors
ForbiddenError()
Creates a generic access-denied error. CallerMember is not captured.
public ForbiddenError()
ForbiddenError(string, string)
[Obsolete("Use ForbiddenError.For(action, resource) for access control errors. This constructor will be removed in a future version.")]
public ForbiddenError(string action, string resource)
Parameters
ForbiddenError(string, string?, string?, int)
public ForbiddenError(string message, string? callerMember = null, string? callerFile = null, int callerLine = 0)
Parameters
Methods
Create(string)
Creates an instance of ForbiddenError with the given message.
public static ForbiddenError Create(string message)
Parameters
messagestring
Returns
CreateNew(string, ImmutableDictionary<string, object>)
Factory method for creating new instances (maintains immutability). Must be implemented by derived classes.
protected override ForbiddenError CreateNew(string message, ImmutableDictionary<string, object> tags)
Parameters
messagestringtagsImmutableDictionary<string, object>
Returns
For(string, string, string?, string?, int)
Creates an access-denied error for a specific action/resource pair, capturing the calling method name automatically.
public static ForbiddenError For(string action, string resource, string? callerMember = null, string? callerFile = null, int callerLine = 0)