Skip to content

DefaultExceptionToErrorInfoConverter implementation ignores customized options AbpExceptionHandlingOptions #24229

@mohamedk-dev

Description

@mohamedk-dev

I'm using ABP 9.3, and I want to show custom error messages with the stack trace and details message for Test environment only
So I set up the configuration in the host module like this:

Configure<AbpExceptionHandlingOptions>(options =>
        {
            var returnExceptionDetails =
                Convert.ToBoolean(configuration["App:Features:AllowReturningExceptionDetailsToClient"]);
            options.SendExceptionsDetailsToClients = returnExceptionDetails;
            options.SendStackTraceToClients = returnExceptionDetails;
        });

I have a custom override for DefaultExceptionToErrorInfoConverter

public class CustomExceptionToErrorConverter(
    IOptions<AbpExceptionLocalizationOptions> localizationOptions,
    IStringLocalizerFactory stringLocalizerFactory,
    IStringLocalizer<AbpExceptionHandlingResource> stringLocalizer,
    IServiceProvider serviceProvider)
    : DefaultExceptionToErrorInfoConverter(
        localizationOptions,
        stringLocalizerFactory,
        stringLocalizer,
        serviceProvider)
{
    protected override RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception,
        AbpExceptionHandlingOptions options)
    {
        var sendExceptionsDetailsToClients = options.SendExceptionsDetailsToClients; // always false
        var sendStackTraceToClients = options.SendStackTraceToClients; // always ture
        
        // rest of the code
    }
}

Related code:

I have to make a temporary solution by injecting IOptions<AbpExceptionHandlingOptions> exceptionHandlingOptions, but I hope this could be fixed in future releases

Thanks

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions