Table of Contents

Interface IExceptionMapper

Namespace
Excalibur.Dispatch
Assembly
Excalibur.Dispatch.Abstractions.dll

Service for mapping exceptions to RFC 7807 Problem Details format.

public interface IExceptionMapper
Extension Methods

Remarks

This service provides the runtime capability to convert exceptions to standardized problem details. It uses the mappings configured via IExceptionMappingBuilder.

The service is thread-safe and designed to be registered as a singleton in the dependency injection container.

Methods

CanMap(Exception)

Determines whether the mapper can handle the specified exception type.

bool CanMap(Exception exception)

Parameters

exception Exception

The exception to check.

Returns

bool

true if a mapping exists for the exception; otherwise, false.

Remarks

Returns true if there is a specific mapping for the exception type, or if the exception is an ApiException and ApiException mapping is enabled. Always returns true if a default mapper is configured.

Map(Exception)

Synchronously maps an exception to problem details.

IMessageProblemDetails Map(Exception exception)

Parameters

exception Exception

The exception to map.

Returns

IMessageProblemDetails

The problem details representing the exception.

Remarks

If a specific mapping exists for the exception type, it will be used. Otherwise, falls back to ToProblemDetails() (if the exception is an ApiException and ApiException mapping is enabled), or the default mapper.

This method should only be used when all registered mappings are synchronous. If async mappings are registered, use MapAsync(Exception, CancellationToken) instead.

MapAsync(Exception, CancellationToken)

Asynchronously maps an exception to problem details.

Task<IMessageProblemDetails> MapAsync(Exception exception, CancellationToken cancellationToken)

Parameters

exception Exception

The exception to map.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<IMessageProblemDetails>

A task that resolves to the problem details representing the exception.

Remarks

Use this method when async mappings may be registered. It properly handles both synchronous and asynchronous mapping functions.