I would like to know how to capture the exceptions I receive from the backend and display them on the frontend. I have a modal where in the OnGet() method I receive the data, in the case that there is a problem with the data from the backend I will have received a UserFriendlyException() exception.
For example:
This is my OnGet() method inside the modal
public async Task OnGet()
{
var data = await _feedOrderLinesAppService.GetListFeedOrderLinesFromDeliveryAsync(Id);
if (data != null)
{
FeedOrderLineBasicInfoDtoViewModel = ObjectMapper.Map<List<FeedOrderLineBasicInfoDto>, List<FeedOrderLineBasicInfoDtoViewModel>>(data);
}
}
Let's review the method GetListFeedOrderLinesFromDeliveryAsync(Id)
public async Task<List<FeedOrderLineBasicInfoDto>> GetListFeedOrderLinesFromDeliveryAsync(string feedDeliveryId)
{
var feedOrderLines = await _feedOrderManager.GetListFeedOrderLinesFromDeliveryAsync(feedDeliveryId);
return ObjectMapper.Map<List<FeedOrderLineWithNavigationProperties>, List<FeedOrderLineBasicInfoDto>>(feedOrderLines);
}
Let's review the method GetListFeedOrderLinesFromDeliveryAsync(feedDeliveryId), This method must first obtain the header ID, and then obtain the lines, but in the case that the header does not exist, it throws an exception.
public async Task<List<FeedOrderLineWithNavigationProperties>> GetListFeedOrderLinesFromDeliveryAsync(string feedOrderHeaderErpId)
{
var feedOrderHeader = await _feedOrderHeaderRepository.FirstOrDefaultAsync(x => x.ErpId == feedOrderHeaderErpId);
if (feedOrderHeader == null)
{
throw new UserFriendlyException("Feed order header not found");
}
return await _feedOrderLineRepository.GetListWithNavigationPropertiesAsync(feedOrderHeaderId: feedOrderHeader.Id);
}
- ABP Framework version: v6.0.1
- UI Type: MVC
- Database System: EF Core ( PostgreSQL)
- Tiered (for MVC) or Auth Server Separated (for Angular): Tiered
- Exception message and full stack trace:
- Steps to reproduce the issue:
1 Answer(s)
-
0
Hello,
Please check similar issue https://abp.io/support/questions/1205/UserFriendlyException#answer-cee7ccee-3ade-8465-ed9b-39fc0543ac0b if it helps you.
Thanks