How to get more detailed exception in ABP?

前端 未结 3 1701
北恋
北恋 2021-01-02 05:18

I created a CrudAppService. When I invoke its dynamic API by using swagger, I get a generic 500 error with this description:



        
3条回答
  •  醉梦人生
    2021-01-02 05:45

    If you use CurrentUnitOfWork, you can catch the exception also and using UserFriendlyException you can throw the desired exception. UserFriendlyException is a specific type of exception so ABP directly shows exception message to the end user.

    Example:

    try
    {
        await _repository.InsertAsync(...);
        await CurrentUnitOfWork.SaveChangesAsync();
    }
    catch(Exception ex)
    {
        throw new UserFriendlyException("user friendly exception message");
    }
    

提交回复
热议问题