Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Reciver proper message from application service's method? #2968


User avatar
0
omital created

Hi. I Call appService's methods from Windows Application with this code:

var res = AsyncHelper.RunSync(() => testClient.Object.GetInstanceInfoByCode(input));

Is it possible to receive ApbUserFriendlyException message created by appService's Method?


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

    Hi,

    For the first option, You can handle AbpRemoteCallException and catch the excpetion. Second way, you can override AbpWebApiClient's PostAsync method. Then derive all of your DTOs in windows app from a base DTO which contains an ErrorInfo field.

    In overriden PostAsync method method, you can handle AbpRemoteCallException and set ErrorInfo of your result DTO.

  • User Avatar
    0
    omital created

    Hi

    For the first option, You can handle AbpRemoteCallException and catch the excpetion.

    I call method like this

    try
                {
                    return await _abpWebApiClient.PostAsync<GetInstanceInfoByCodeOutput>(BaseUrl + "api/services/isirids/dashboard/GetInstanceInfoByCode", input);
                }
                catch (AbpRemoteCallException ex)
                {
                    throw new Exception(ex.Message);
                }
    

    for every exception raised from server I got this

    Could not made request to http://localhost/ISD.Web//api/services/isirids/dashboard/GetInstanceInfoByCode! StatusCode: InternalServerError, ReasonPhrase: Internal Server Error
    

    AND for secend way, Please example?! :shock:

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In order to go with my second suggestion the error message should not contain

    ReasonPhrase: Internal Server Error
    

    So maybe I'm wrong, let me check it again and get back to you.

    Thanks.

  • User Avatar
    0
    omital created

    any solution?!

  • User Avatar
    0
    hikalkan created
    Support Team

    Why not just try-catch it since application service's exceptions are not caught by the framework for a Windows application. (As I understand you directly use app service from a windows desktop app)

  • User Avatar
    0
    omital created

    Yes. I use app service from windows desktop app directly. Is it correct way? if yes, how windows app can know about actual error occurred in service?

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Yes, this is the correct way.

    how windows app can know about actual error occurred in service

    You already directly catch the exception without any filtering. So, you can know the error details. Always use application service inside a try-catch method (and probably you want to show the error message to the user in the catch block).