Base solution for your next web application
Open Closed

How to return custom status and message from AppService? #5938


User avatar
0
mirzanas created

How can I return custom status (404 or any another) and custom exception(or message) using AppService from backend. Example: UI call back-end get method and backend did't find needed data or some bussines validation accure, so I want return the status 404, with my exception message, but I don't want that ui treat this like usual exception and show UI standart exception modal, better for me that I could provide custom behavior for user?


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

    https://github.com/aspnetboilerplate/aspnetboilerplate/blob/95b19dbce4a9785fdac1d6f5ca74fa16dd690eeb/src/Abp.AspNetCore/AspNetCore/Mvc/Results/AbpResultFilter.cs#L22

    https://github.com/aspnetboilerplate/aspnetboilerplate/blob/354d66d76f63391ee3fd524d7cd35a1701fd3b71/src/Abp.AspNetCore/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs#L69

    You can override the AbpResultFilter and customize the status code.

    Use UserFriendlyException custom message .

  • User Avatar
    0
    mirzanas created

    but this both methods is inside the nuget package, so how I should deal with them?

  • User Avatar
    1
    aaron created
    Support Team

    Override (and replace), not modify.

    Implement IResultFilter and replace AbpResultFilter: https://stackoverflow.com/questions/47888802/disable-wrapping-of-controller-results

    Override and replace AbpExceptionFilter: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3280

  • User Avatar
    0
    mirzanas created

    Thanks, I would try.