Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override exception message to respone from ABP farmework #16893

Closed
manojkrsna opened this issue Jun 20, 2023 · 5 comments
Closed

How to override exception message to respone from ABP farmework #16893

manojkrsna opened this issue Jun 20, 2023 · 5 comments

Comments

@manojkrsna
Copy link

How to override exception message to respone through ABP farmework commonly

Have tried the things which is in below link but it was only to read. Please help here.

https://docs.abp.io/en/abp/latest/Exception-Handling#subscribing-to-the-exceptions

@berkansasmaz
Copy link
Member

berkansasmaz commented Jun 20, 2023

Just override the relevant localization strings.

For example, for internal server error message, you need to override InternalServerErrorMessage localization string. You can find the relevant localization keys here.

@manojkrsna
Copy link
Author

manojkrsna commented Jun 22, 2023

I tried with below code and the exception is not going through this class. My requirement not to just change localization string , need to change few things here

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IExceptionToErrorInfoConverter), typeof(DefaultExceptionToErrorInfoConverter), typeof(CustomExceptionToErrorInfoConverter))]
public class CustomExceptionToErrorInfoConverter : DefaultExceptionToErrorInfoConverter
{
 // CODE
 }

@manojkrsna
Copy link
Author

manojkrsna commented Jun 22, 2023

It worked when i made below changes

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IExceptionToErrorInfoConverter), typeof(DefaultExceptionToErrorInfoConverter), typeof(CustomExceptionToErrorInfoConverter))]
public class CustomExceptionToErrorInfoConverter : DefaultExceptionToErrorInfoConverter
{
// Code
}

to

public class CustomExceptionToErrorInfoConverter : : IExceptionToErrorInfoConverter, ITransientDependency
{
// Code
}

Please explain why is it so, this should work with Dependency and ExposeServices Attributes right and this is working with out those?

@berkansasmaz
Copy link
Member

Glad it worked after recent changes 🥳

In response to your question, the code that shows how to override an example method like the one below should work.

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(DefaultExceptionToErrorInfoConverter), typeof(IExceptionToErrorInfoConverter))]
public class CustomExceptionToErrorInfoConverter : DefaultExceptionToErrorInfoConverter
{

    protected override RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception, AbpExceptionHandlingOptions options)
    {
        // code
    }

}

Closing the issue. Feel free to re-open or create a new issue if you have further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants