Class ForbiddenError

Namespace
REslava.Result
Assembly
REslava.Result.dll

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

action string
resource string

ForbiddenError(string, string?, string?, int)

public ForbiddenError(string message, string? callerMember = null, string? callerFile = null, int callerLine = 0)

Parameters

message string
callerMember string
callerFile string
callerLine int

Methods

Create(string)

Creates an instance of ForbiddenError with the given message.

public static ForbiddenError Create(string message)

Parameters

message string

Returns

ForbiddenError

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

message string
tags ImmutableDictionary<string, object>

Returns

ForbiddenError

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)

Parameters

action string
resource string
callerMember string
callerFile string
callerLine int

Returns

ForbiddenError