Base solution for your next web application
Open Closed

Custom exception message #6000


User avatar
0
antonis created

Hi,

I want to send a custom exception message to client when a specific exception is fired (AbpDbConcurrencyException). Instead of doing this for each method of all my appservices I would like to change it in a global place. So for example if I have 20 AppServices with each 2-3 methods I dont want to add try/catch block in each method but instead have a place where I do this.

How can I achieve such requirement

Thanks

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @

    You can define a custom ExceptionFilter, see https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3280

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    antonis created

    @ismcagdas The link you sent me does not show how can you change the exception message.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    1
    ismcagdas created
    Support Team

    Hi @antonis

    If you define such an exception filter and set it's order to 1 as explained here https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3280#issuecomment-382609585 it will be executed before other filters.

    In your custom exception filter you can only catch AbpDbConcurrencyException and then throw UserFriendlyException with an appropriate message. Then, it should work like you want.

    Let me know If it doesn't work for you.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    antonis created

    Thank you @ismcagdas

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)