You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe the problem.
Is there a way to customize error responses and log levels for specific exceptions in ABP Framework?
Description
I need to handle two requirements for specific exceptions in ABP Framework:
Return customized error messages to clients.
Adjust the log level for specific exception types (e.g., reduce Error to Warning).
Use Case Example
When a database unique constraint violation occurs (e.g., duplicate entry for a unique index), I want to:
Return a user-friendly message like "A subject with the same name already exists".
Change the log level from the default Error to Warning.
Current Implementation for Custom Error Messages
I implemented a custom ExceptionToErrorInfoConverter to handle database unique constraint errors:
[Dependency(ReplaceServices=true)]publicclassCustomExceptionConverter:DefaultExceptionToErrorInfoConverter{publicCustomExceptionConverter(IOptions<AbpExceptionLocalizationOptions>localizationOptions,IStringLocalizerFactorystringLocalizerFactory,IStringLocalizer<AbpExceptionHandlingResource>stringLocalizer,IServiceProviderserviceProvider):base(localizationOptions,stringLocalizerFactory,stringLocalizer,serviceProvider){}protectedoverrideRemoteServiceErrorInfoCreateErrorInfoWithoutCode(Exceptionexception,AbpExceptionHandlingOptionsoptions){if(!options.SendExceptionsDetailsToClients){exception=TryToGetActualException(exception);if(exceptionisDbUpdateExceptiondbEx&&dbEx.InnerExceptionisSqlExceptionsqlEx&&sqlEx.Message.Contains("unique constraint 'IX_Subjects_Name_OrganizationUnitId'")){returnnewRemoteServiceErrorInfo("A subject with the same name already exists in the current organization");}}returnbase.CreateErrorInfoWithoutCode(exception,options);}}
About log level customization
The above are just examples that I have come up with so far, I don't know if there is a better idea in ABP, I found the source code for the log level,
When a database unique constraint violation occurs
You can try to check before inserting it into the database.
Well, can.
But I also met a problem, most of the time, passed non-existent user front-end to the back-end, will trigger a 404 Error, log will print Volo. Abp. Domain. Entities. EntityNotFoundException, LogLevel = Error, I think to a Warning
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Is there a way to customize error responses and log levels for specific exceptions in ABP Framework?
Description
I need to handle two requirements for specific exceptions in ABP Framework:
Error
toWarning
).Use Case Example
When a database unique constraint violation occurs (e.g., duplicate entry for a unique index), I want to:
Error
toWarning
.Current Implementation for Custom Error Messages
I implemented a custom
ExceptionToErrorInfoConverter
to handle database unique constraint errors:About log level customization
The above are just examples that I have come up with so far, I don't know if there is a better idea in ABP, I found the source code for the log level,
This doesn't get what I want, I need to rewrite the whole method to get there, is there an easier way?
Describe the solution you'd like
ABP has a ready-made configurable way to define the error level and change the text returned by the error
Additional context
No response
The text was updated successfully, but these errors were encountered: