Open Closed

UserFriendlyException thrown in domain event returns "Error: response status is 200" #3442


User avatar
1
Josh.Cunningham created

Throwing a UserFriendlyException from a local domain event results in http response with detail "Error: response status is 200".

  • ABP Framework version: v5.3.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): Tiered
  • Exception message and stack trace:
    2022-07-18 10:09:34.558 +01:00 [WRN] An exception occurred, but response has already started!
    2022-07-18 10:09:34.581 +01:00 [ERR] An unhandled exception has occurred while executing the request.
    Volo.Abp.UserFriendlyException: Cannot create a Book
    at Acme.BookStore.Books.BookCreateHandler.HandleEventAsync(EntityCreatedEventData1 eventData) in C:\_git\AbpDomainEventException\src\Acme.BookStore.Domain\Books\Book.cs:line 22
    at Volo.Abp.EventBus.EventHandlerInvoker.InvokeAsync(IEventHandler eventHandler, Object eventData, Type eventType)
    at Volo.Abp.EventBus.EventBusBase.TriggerHandlerAsync(IEventHandlerFactory asyncHandlerFactory, Type eventType, Object eventData, List1 exceptions, InboxConfig inboxConfig)
    at Volo.Abp.EventBus.EventBusBase.ThrowOriginalExceptions(Type eventType, List1 exceptions)
    at Volo.Abp.EventBus.EventBusBase.TriggerHandlersAsync(Type eventType, Object eventData)
    at Volo.Abp.EventBus.Local.LocalEventBus.PublishAsync(LocalEventMessage localEventMessage)
    at Volo.Abp.EventBus.Local.LocalEventBus.PublishToEventBusAsync(Type eventType, Object eventData)
    at Volo.Abp.EventBus.EventBusBase.PublishAsync(Type eventType, Object eventData, Boolean onUnitOfWorkComplete)
    at Volo.Abp.EventBus.UnitOfWorkEventPublisher.PublishLocalEventsAsync(IEnumerable1 localEvents)
    at Volo.Abp.Uow.UnitOfWork.CompleteAsync(CancellationToken cancellationToken)
    at Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c\_\_DisplayClass6\_1.<b\_\_1>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c\_\_DisplayClass6\_1.<b\_\_1>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Volo.Abp.AspNetCore.MultiTenancy.MultiTenancyMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c\_\_DisplayClass6\_1.<b\_\_1>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Microsoft.AspNetCore.Builder.ApplicationBuilderAbpJwtTokenMiddlewareExtension.<>c\_\_DisplayClass0\_0.<b\_\_0>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
    at Volo.Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c\_\_DisplayClass6\_1.<b\_\_1>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c\_\_DisplayClass6\_1.<b\_\_1>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
    at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c\_\_DisplayClass6\_1.<b\_\_1>d.MoveNext()
    \-\-\- End of stack trace from previous location \-\-\-
    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
    at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context)
    at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT\`\`1.ProcessRequestAsync()
    2022-07-18 10:09:34.581 +01:00 [WRN] The response has already started, the error page middleware will not be executed.
  • Repro Steps:
    1. Created a new solution (Acme.BookStore) with ABP CLI
    2. Generated CRUD entity (Book) and pages with ABP Suite
    3. Created a LocalEventHandler to handle EntityCreatedEventData for the generated entity that throws a UserFriendlyException
    4. Doing POST /api/app/books via swagger results in a response with with an undocumented code and details stating "Error: response status is 200":
    5. Creating an entity from the generated create modal displays a dialog stating "An error has occurred! Error detail not sent by server":
    6. We would like both of these scenarios to display a more appropriate response, any help would be greatly appreciated

Thanks in advance


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Doing POST /api/app/books via swagger results in a response with with an undocumented code and details stating "Error: response status is 200":

    When ILocalEventHandler throws an exception, the HTTP response has already been written. We cannot change it anymore.

    Creating an entity from the generated create modal displays a dialog stating "An error has occurred! Error detail not sent by server"

    handles an exception that returns an object result (not a view result).

    public async Task<NoContentResult> OnPostAsync()
    {
    
        await _booksAppService.CreateAsync(Book);
        return NoContent();
    }
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09