protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception, ExceptionHandlingOptions options)
    {
        if (options.SendExceptionsDetailsToClients)
        {
            return(CreateDetailedErrorInfoFromException(exception, options.SendStackTraceToClients));
        }

        exception = TryToGetActualException(exception);

        if (exception is RemoteCallException remoteCallException && remoteCallException.Error != null)
        {
            return(remoteCallException.Error);
        }

        if (exception is DbConcurrencyException)
        {
            return(new RemoteServiceErrorInfo(L["DbConcurrencyErrorMessage"]));
        }

        if (exception is EntityNotFoundException)
        {
            return(CreateEntityNotFoundError(exception as EntityNotFoundException));
        }

        var errorInfo = new RemoteServiceErrorInfo();

        if (exception is UserFriendlyException || exception is RemoteCallException)
        {
            errorInfo.Message = exception.Message;
            errorInfo.Details = (exception as IHasErrorDetails)?.Details;
        }

        if (exception is IHasValidationErrors)
        {
            if (errorInfo.Message.IsNullOrEmpty())
            {
                errorInfo.Message = L["ValidationErrorMessage"];
            }

            if (errorInfo.Details.IsNullOrEmpty())
            {
                errorInfo.Details = GetValidationErrorNarrative(exception as IHasValidationErrors);
            }

            errorInfo.ValidationErrors = GetValidationErrorInfos(exception as IHasValidationErrors);
        }

        TryToLocalizeExceptionMessage(exception, errorInfo);

        if (errorInfo.Message.IsNullOrEmpty())
        {
            errorInfo.Message = L["InternalServerErrorMessage"];
        }

        errorInfo.Data = exception.Data;

        return(errorInfo);
    }
        protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception, bool includeSensitiveDetails)
        {
            if (includeSensitiveDetails)
            {
                return(CreateDetailedErrorInfoFromException(exception));
            }

            exception = TryToGetActualException(exception);

            if (exception is AbpRemoteCallException remoteCallException)
            {
                return(remoteCallException.Error);
            }

            if (exception is AbpDbConcurrencyException)
            {
                return(new RemoteServiceErrorInfo(L["AbpDbConcurrencyErrorMessage"]));
            }

            if (exception is EntityNotFoundException)
            {
                return(CreateEntityNotFoundError(exception as EntityNotFoundException));
            }

            var errorInfo = new RemoteServiceErrorInfo();

            if (exception is IUserFriendlyException)
            {
                errorInfo.Message = exception.Message;
                errorInfo.Details = (exception as IHasErrorDetails)?.Details;
            }

            if (exception is IHasValidationErrors)
            {
                if (errorInfo.Message.IsNullOrEmpty())
                {
                    errorInfo.Message = L["ValidationErrorMessage"];
                }

                if (errorInfo.Details.IsNullOrEmpty())
                {
                    errorInfo.Details = GetValidationErrorNarrative(exception as IHasValidationErrors);
                }

                errorInfo.ValidationErrors = GetValidationErrorInfos(exception as IHasValidationErrors);
            }

            TryToLocalizeExceptionMessage(exception, errorInfo);

            if (errorInfo.Message.IsNullOrEmpty())
            {
                errorInfo.Message = L["InternalServerErrorMessage"];
            }

            errorInfo.Data = exception.Data;

            return(errorInfo);
        }
예제 #3
0
 protected override void TryToLocalizeExceptionMessage(Exception exception, RemoteServiceErrorInfo errorInfo)
 {
     base.TryToLocalizeExceptionMessage(exception, errorInfo);
     // 500错误,显示错误简要信息
     if (errorInfo.Message.IsNullOrEmpty())
     {
         errorInfo.Message = exception.Message;
     }
 }
예제 #4
0
        /// <summary>
        /// 创建错误信息(无错误码)
        /// </summary>
        /// <param name="exception">异常</param>
        /// <param name="includeSensitiveDetails">是否包含敏感信息</param>
        protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception, bool includeSensitiveDetails)
        {
            exception = TryToGetActualException(exception);

            var errorInfo = new RemoteServiceErrorInfo();

            errorInfo.Data = exception.Data;

            return(errorInfo);
        }
예제 #5
0
 protected virtual async Task ShowErrorInfoAsync(RemoteServiceErrorInfo errorInfo)
 {
     if (errorInfo.Details.IsNullOrEmpty())
     {
         await MessageService.ErrorAsync(errorInfo.Message);
     }
     else
     {
         await MessageService.ErrorAsync(errorInfo.Details, errorInfo.Message);
     }
 }
        protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception)
        {
            if (ExceptionHandlingOptions.SendExceptionsDetailsToClients)
            {
                return(CreateDetailedErrorInfoFromException(exception));
            }

            exception = TryToGetActualException(exception);

            if (exception is EntityNotFoundException)
            {
                return(CreateEntityNotFoundError(exception as EntityNotFoundException));
            }

            if (exception is AbpAuthorizationException)
            {
                var authorizationException = exception as AbpAuthorizationException;
                return(new RemoteServiceErrorInfo(authorizationException.Message));
            }

            var errorInfo = new RemoteServiceErrorInfo();

            if (exception is IUserFriendlyException)
            {
                errorInfo.Message = exception.Message;
                errorInfo.Details = (exception as IHasErrorDetails)?.Details;
            }

            if (exception is IHasValidationErrors)
            {
                if (errorInfo.Message.IsNullOrEmpty())
                {
                    errorInfo.Message = L["ValidationErrorMessage"];
                }

                if (errorInfo.Details.IsNullOrEmpty())
                {
                    errorInfo.Details = GetValidationErrorNarrative(exception as IHasValidationErrors);
                }

                errorInfo.ValidationErrors = GetValidationErrorInfos(exception as IHasValidationErrors);
            }

            TryToLocalizeExceptionMessage(exception, errorInfo);

            if (errorInfo.Message.IsNullOrEmpty())
            {
                errorInfo.Message = L["InternalServerErrorMessage"];
            }

            errorInfo.Data = exception.Data;

            return(errorInfo);
        }
    protected virtual void TryToLocalizeExceptionMessage(Exception exception, RemoteServiceErrorInfo errorInfo)
    {
        //if (exception is ILocalizeErrorMessage localizeErrorMessageException)
        //{
        //    using (var scope = ServiceProvider.CreateScope())
        //    {
        //        errorInfo.Message = localizeErrorMessageException.LocalizeMessage(new LocalizationContext(scope.ServiceProvider));
        //    }

        //    return;
        //}

        if (!(exception is IHasErrorCode exceptionWithErrorCode))
        {
            return;
        }

        if (exceptionWithErrorCode.Code.IsNullOrWhiteSpace() ||
            !exceptionWithErrorCode.Code.Contains(":"))
        {
            return;
        }

        var codeNamespace = exceptionWithErrorCode.Code.Split(':')[0];

        var localizationResourceType = LocalizationOptions.ErrorCodeNamespaceMappings.GetOrDefault(codeNamespace);

        if (localizationResourceType == null)
        {
            return;
        }

        var stringLocalizer = StringLocalizerFactory.Create(localizationResourceType);
        var localizedString = stringLocalizer[exceptionWithErrorCode.Code];

        if (localizedString.ResourceNotFound)
        {
            return;
        }

        var localizedValue = localizedString.Value;

        if (exception.Data != null && exception.Data.Count > 0)
        {
            foreach (var key in exception.Data.Keys)
            {
                localizedValue = localizedValue.Replace("{" + key + "}", exception.Data[key]?.ToString());
            }
        }

        errorInfo.Message = localizedValue;
    }
        public AbpDaprActorCallException(RemoteServiceErrorInfo error)
            : base(error.Message)
        {
            Error = error;

            if (error.Data != null)
            {
                foreach (var dataKey in error.Data.Keys)
                {
                    Data[dataKey] = error.Data[dataKey];
                }
            }
        }
예제 #9
0
    public RemoteCallException(RemoteServiceErrorInfo error, Exception innerException = null)
        : base(error.Message, innerException)
    {
        Error = error;

        if (error.Data != null)
        {
            foreach (var dataKey in error.Data.Keys)
            {
                Data[dataKey] = error.Data[dataKey];
            }
        }
    }
        protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception)
        {
            if (SendAllExceptionsToClients)
            {
                return(CreateDetailedErrorInfoFromException(exception));
            }

            exception = TryToGetActualException(exception);

            if (exception is EntityNotFoundException)
            {
                return(CreateEntityNotFoundError(exception as EntityNotFoundException));
            }

            if (exception is AbpAuthorizationException)
            {
                var authorizationException = exception as AbpAuthorizationException;
                return(new RemoteServiceErrorInfo(authorizationException.Message));
            }

            var errorInfo = new RemoteServiceErrorInfo();

            if (exception is IUserFriendlyException)
            {
                var userFriendlyException = exception as IUserFriendlyException;
                errorInfo.Message = userFriendlyException.Message;
                errorInfo.Details = userFriendlyException.Details;
            }

            if (exception is IHasValidationErrors)
            {
                if (errorInfo.Message.IsNullOrEmpty())
                {
                    errorInfo.Message = L("ValidationError");
                }

                if (errorInfo.Details.IsNullOrEmpty())
                {
                    errorInfo.Details = GetValidationErrorNarrative(exception as IHasValidationErrors);
                }

                errorInfo.ValidationErrors = GetValidationErrorInfos(exception as IHasValidationErrors);
            }

            if (errorInfo.Message.IsNullOrEmpty())
            {
                errorInfo.Message = L("InternalServerError");
            }

            return(errorInfo);
        }
    protected virtual RemoteServiceErrorInfo CreateDetailedErrorInfoFromException(Exception exception, bool sendStackTraceToClients)
    {
        var detailBuilder = new StringBuilder();

        AddExceptionToDetails(exception, detailBuilder, sendStackTraceToClients);

        var errorInfo = new RemoteServiceErrorInfo(exception.Message, detailBuilder.ToString());

        if (exception is ValidationException)
        {
            errorInfo.ValidationErrors = GetValidationErrorInfos(exception as ValidationException);
        }

        return(errorInfo);
    }
예제 #12
0
        protected virtual RemoteServiceErrorInfo CreateErrorInfoWithoutCode(Exception exception)
        {
            if (SendAllExceptionsToClients)
            {
                return(CreateDetailedErrorInfoFromException(exception));
            }
            else
            {
                exception = TryToGetActualException(exception);
                if (exception is EntityNotFoundException)
                {
                    return(CreateEntityNotFoundError(exception as EntityNotFoundException));
                }
                else if (exception is XpressAuthorizationException)
                {
                    var authorizationException = exception as XpressAuthorizationException;
                    return(new RemoteServiceErrorInfo(authorizationException.Message));
                }
                else
                {
                    var errorInfo = new RemoteServiceErrorInfo();
                    if (exception is IHasValidationErrors)
                    {
                        if (errorInfo.Details.IsNullOrEmpty())
                        {
                            errorInfo.Details = GetValidationErrorNarrative(exception as IHasValidationErrors);
                        }

                        errorInfo.ValidationErrors = GetValidationErrorInfos(exception as IHasValidationErrors);
                    }

                    if (exception is IUserFriendlyException)
                    {
                        errorInfo.Message = exception.Message;
                        errorInfo.Details = (exception as IHasErrorDetails)?.Details;
                    }
                    else
                    {
                        errorInfo.Message = "远程服务异常";
                        errorInfo.Details = exception.Message;
                    }

                    return(errorInfo);
                }
            }
        }
 public AbpRemoteCallException(RemoteServiceErrorInfo error)
     : base(error.Message)
 {
     Error = error;
 }
 /// <summary>
 /// 初始化一个<see cref="RemoteServiceErrorResponse"/>类型的实例
 /// </summary>
 /// <param name="error">远程服务错误信息</param>
 public RemoteServiceErrorResponse(RemoteServiceErrorInfo error) => Error = error;