Open Closed

Catch BusinessException from IDistributedEventHandler #8838


User avatar
0
badassgr1 created

Hi, i'd like to catch a BusinessException in a DistributedHandler(IDistributedEventHandler) from an api call , i put [UnitOfWork(true)] attribute in both classes and verify i m in same uow but i only got error : TypeError: Failed to fetch, Any clue ? Thanks. Fred.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi,

    Can you provide sample codes that explains your case?

    As I uınderstand, you inject a service inside your EventHandler and trying to catch exception that is thrown in that injected service or any of it's dependencies, right?

    Normally you can catch them, if you do not catch and throw an exception from a handler, that makes that execution is failed and it'll be re-tried. If you don't want to execute that handler again, you should handle and don't throw exception in the handler

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    badassgr1 created

    Hi enisn :

    for example i got a IDistributedEventHandler witch got an error

    public class OrderHandler : IDistributedEventHandler, ITransientDependency
    {
        private readonly OrderReservationManager _orderReservationManager;
    
    
        public OrderHandler(OrderReservationManager orderReservationManager)
        {
            _orderReservationManager = orderReservationManager;
        }
    
        public async Task HandleEventAsync(OrderEto eventData)
        {
            _orderReservationManager.ThrowError();
        }
    }
    

    call by this from another domain :

    public class StockAppService : IStockAppService
    {
        private readonly IStockRepository _stockRepository;
        public StockAppService(IStockRepository stockRepository)
        {
         _stockRepository = stockRepository;
        }
    
        public virtual async Task<Guid> OrderItemAsync(FieldPlanCreateDto input)
        {
            await _stockRepository.UpdateStock(input.item);
            AddDistributedEvent(new OrderEto
            {
                Item = input.item
            });		
        }
    }
    

    if i got an error on StockAppService , error is return correctly(_AbpErrorFormat, error.Data in json) but an error HandleEventAsync always return TypeError: Failed to fetch.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Are they running on the same instance of application? Or you're using in a micro-service project?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.