Open Closed

"An error has occurred" message appears even though BusinessException is thrown #3202


User avatar
0
ademaygun created
  • ABP Framework version: v5.1.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:

I am getting error when submit a record on UI page ("An error occured"):

and AbpAuditLogs.exceptions :

[
  {
    "code": "Xproject:00132",
    "message": "Exception of type 'MyCompany.Xproject.Domain.Addresses.Exceptions.TaxOfficeNotMatchException' was thrown.",
    "details": "TaxOfficeNotMatchException: Exception of type 'MyCompany.Xproject.Domain.Addresses.Exceptions.TaxOfficeNotMatchException' was thrown.\nSTACK TRACE:    at MyCompany.Xproject.Addresses.AddressManager.CheckTaxOfficeAsync(String taxOffice) in C:\\MyCompany\\Repos\\MyCompany.ECOM.Misc\\MyCompany.Xproject\\aspnet-core\\src\\MyCompany.Xproject.Domain\\Addresses\\AddressManager.cs:line 120\n   at MyCompany.Xproject.Addresses.AddressManager.CreateAsync(Int32 countryId, Nullable`1 municipalityId, Nullable`1 neighbourhoodId, Nullable`1 parentId, Nullable`1 cityId, String salutation, String contactName, String contactSurName, String countryPhonePrefix, String phone, String eMail, String companyTitle, String companyDepartment, String iossNr, String postalCode, String addressText, String taxOffice, String taxNr, String idNr, IndividualCorporateType individualCorporateTypeId, DeliveryType deliveryTypeId, Decimal code, Nullable`1 adressTypeId, Boolean deliveryAndInvoiceAddressSame) in C:\\MyCompany\\Repos\\MyCompany.ECOM.Misc\\MyCompany.Xproject\\aspnet-core\\src\\MyCompany.Xproject.Domain\\Addresses\\AddressManager.cs:line 55\n   at MyCompany.Xproject.Addresses.AddressesAppService.CreateAsync(AddressCreateDto input) in C:\\MyCompany\\Repos\\MyCompany.ECOM.Misc\\MyCompany.Xproject\\aspnet-core\\src\\MyCompany.Xproject.Application\\Addresses\\AddressAppService.cs:line 263\n   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)\n   at 

but message in logs.txt looks like it should

2022-06-07 14:36:18.774 +03:00 [WRN] ---------- RemoteServiceErrorInfo ----------
{
  "code": "Xproject:00132",
  "message": "Vergi Dairesi Alanı Eşleşmedi",
  "details": null,
  "data": {},
  "validationErrors": null
}

2022-06-07 14:36:18.774 +03:00 [WRN] Exception of type 'MyCompany.Xproject.Domain.Addresses.Exceptions.TaxOfficeNotMatchException' was thrown.
MyCompany.Xproject.Domain.Addresses.Exceptions.TaxOfficeNotMatchException: Exception of type 'MyCompany.Xproject.Domain.Addresses.Exceptions.TaxOfficeNotMatchException' was thrown.
   at MyCompany.Xproject.Addresses.AddressManager.CheckTaxOfficeAsync(String taxOffice) in C:\MyCompany\Repos\MyCompany.ECOM.Misc\MyCompany.Xproject\aspnet-core\src\MyCompany.Xproject.Domain\Addresses\AddressManager.cs:line 120
   at MyCompany.Xproject.Addresses.AddressManager.CreateAsync(Int32 countryId, Nullable`1 municipalityId, Nullable`1 

I don't manage exception manually. (there is no any try-catch block)

private async Task CheckTaxOfficeAsync(string taxOffice)
        {
            if (!string.IsNullOrEmpty(taxOffice))
            {
                var address = (await _taxOfficeRepository.GetQueryableAsync()).Any(x => x.Name == taxOffice);
                if (!address)
                {
                    throw new TaxOfficeNotMatchException();
                }
            }
        }
public class TaxOfficeNotMatchException : BusinessException
    {
        public TaxOfficeNotMatchException()
            : base(XprojectErrorCodes.XprojectTaxOfficeNotMatchError)
        {
        }
    }

5 Answer(s)
  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    Sorry, I couldn't understand your question.

    Are you asking that you have a TaxOfficeNotMatchException business exception that is logged correctly but why do you get a generic error modal and not a detailed error modal?

    If that is the case, you need to catch the business exception and throw a UserFriendlyException.

    Although, If I have misunderstood, can you explain more of your intention?

  • User Avatar
    0
    ademaygun created

    I realise user may send me wrong modal screenshot, so we discard ui side of problem for now.

    I want to ask while logs.txt is like i am expecting, why AbpAuditLogs different than logs.txt like below

    logs.txt (as expecting) :

    "code": "Xproject:00132",
    "message": "Vergi Dairesi Alanı Eşleşmedi",
    
    

    AbpAuditLogs :

    "code": "Xproject:00132",
    "message": "Exception of type 'MyCompany.Xproject.Domain.Addresses.Exceptions.TaxOfficeNotMatchException' was thrown.",
    
  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    I see your point. Audit log message should also be the error message instead of type. It is a valid request and I will create an internal issue about it.

    Thank you.

  • User Avatar
    0
    ademaygun created

    In my opinion

    DefaultExceptionToErrorInfoConverter.cs:

    protected virtual Exception TryToGetActualException(Exception exception)
        {
            if (exception.InnerException != null)
            {
                if (exception.InnerException is AbpValidationException ||
                    exception.InnerException is AbpAuthorizationException ||
                    exception.InnerException is EntityNotFoundException ||
                    exception.InnerException is IBusinessException)
                {
                    return exception.InnerException;
                }
            }
            return exception;
        }
    

    instead of :

    protected virtual Exception TryToGetActualException(Exception exception)
        {
            if (exception is AggregateException && exception.InnerException != null)
            {
                var aggException = exception as AggregateException;
                if (aggException.InnerException is AbpValidationException ||
                    aggException.InnerException is AbpAuthorizationException ||
                    aggException.InnerException is EntityNotFoundException ||
                    aggException.InnerException is IBusinessException)
                {
                    return aggException.InnerException;
                }
            }
            return exception;
        }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We fixed it. See https://github.com/abpframework/abp/pull/12957

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11