Table of Contents

Class ConflictException

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

Exception thrown when an operation conflicts with the current state of a resource.

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

Examples

if (await repository.ExistsAsync(user.Email, cancellationToken))
{
    throw new ConflictException("User", "email", "A user with this email already exists.");
}

Remarks

This exception indicates that the requested operation cannot be completed because it would conflict with the current state of the target resource. It maps to HTTP status code 409 (Conflict).

Use this exception when:

  • Attempting to create a resource that already exists
  • Modifying a resource in a way that violates business rules
  • State transition is not allowed from the current state

For optimistic locking failures (version mismatches), use ConcurrencyException instead.

Constructors

ConflictException()

Initializes a new instance of the ConflictException class.

public ConflictException()

ConflictException(string)

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

public ConflictException(string message)

Parameters

message string

The error message that explains the reason for the exception.

ConflictException(string, Exception?)

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

public ConflictException(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.

ConflictException(string, string, string)

Initializes a new instance of the ConflictException class with resource and field information.

public ConflictException(string resource, string field, string reason)

Parameters

resource string

The type or name of the resource involved in the conflict.

field string

The field that caused the conflict.

reason string

The reason for the conflict.

Properties

Field

Gets the field that caused the conflict, if applicable.

public string? Field { get; protected init; }

Property Value

string

The field name, or null if not specified.

Reason

Gets the reason for the conflict.

public string? Reason { get; protected init; }

Property Value

string

The conflict reason, or null if not specified.

Methods

AlreadyExists(string, string)

Creates a ConflictException for a duplicate resource scenario.

public static ConflictException AlreadyExists(string resource, string identifier)

Parameters

resource string

The type or name of the resource.

identifier string

The identifier that already exists.

Returns

ConflictException

A new ConflictException instance.

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.

InvalidStateTransition(string, string, string)

Creates a ConflictException for an invalid state transition.

public static ConflictException InvalidStateTransition(string resource, string currentState, string targetState)

Parameters

resource string

The type or name of the resource.

currentState string

The current state.

targetState string

The desired target state.

Returns

ConflictException

A new ConflictException instance.

WithReason(string, string)

Creates a ConflictException with resource and reason information.

public static ConflictException WithReason(string resource, string reason)

Parameters

resource string

The type or name of the resource involved in the conflict.

reason string

The reason for the conflict.

Returns

ConflictException

A new ConflictException instance.