public void ctor_Paramsのエラーパラメーターだけのコンストラクタではデフォルトのメッセージが設定される()
    {
        using var cul = TestHelper.SetEnglishCulture();
        var er = new AggregateError(new Error(), new Error());

        er.Message.Should().Be("Raise multiple errors.");
    }
    public void ctor_エラーパラメーターだけのコンストラクタではデフォルトのメッセージが設定される()
    {
        using var cul = TestHelper.SetEnglishCulture();
        var er = new AggregateError(Enumerable.Empty <IError>());

        er.Message.Should().Be("Raise multiple errors.");
    }
Exemplo n.º 3
0
        public void Constructor_maps_arguments()
        {
            var errors = new List <Error>();

            var aggregate = new AggregateError(errors);

            aggregate.Errors.Should().NotBeNull();
            aggregate.Errors.Equals(errors);
            aggregate.Code.Should().Be(default(int?));
            aggregate.Data.Should().Be(default);
    public void Errors_コンストラクタで設定した値が取得できる()
    {
        var e1 = new Error();
        var e2 = new Error();
        var e3 = new Error();

        var er = new AggregateError(e1, e2, e3);

        er.Errors.IndexOf(e1).Should().Be(0);
        er.Errors.IndexOf(e2).Should().Be(1);
        er.Errors.IndexOf(e3).Should().Be(2);
    }
Exemplo n.º 5
0
 internal void AccumulateCore(object item)
 {
     if (this.error == null)
     {
         try
         {
             this.AccumulateOverride(item);
         }
         catch
         {
             this.error = AggregateValue.Error;
         }
     }
 }
Exemplo n.º 6
0
    public IError OnError(IError error)
    {
        if (error.Exception is ValidationException vx)
        {
            var childErrors =
                vx.Errors.Select(x => new FluentValidationProblemDetail(x))
                .Select(
                    x => new Error(x.ErrorMessage)
                    .WithCode(x.ErrorCode)
                    .SetExtension("severity", x.Severity.ToString())
                    .SetExtension("attemptedValue", x.AttemptedValue)
                    .SetExtension("field", x.PropertyName)
                    .SetExtension("propertyName", x.PropertyName)
                    );
            var result = new AggregateError(childErrors);
            return(result);
        }

        if (error.Exception is IProblemDetailsData ex)
        {
            var builder = ErrorBuilder.FromError(error);
            builder
            .SetException(error.Exception)
            .SetMessage(error.Exception.Message)
            .WithProblemDetails(ex);

            if (error.Exception is NotFoundException)
            {
                builder.SetCode("NOTFOUND");
            }

            if (error.Exception is NotAuthorizedException)
            {
                builder.SetCode("NOTAUTHORIZED");
            }

            if (error.Exception is RequestFailedException)
            {
                builder.SetCode("FAILED");
            }

            return(builder.Build());
        }

        return(error);
    }
Exemplo n.º 7
0
 internal void MergeCore(AggregateValue childAggregate)
 {
     try
     {
         if (childAggregate.error != null)
         {
             this.error = childAggregate.error;
         }
         else
         {
             this.MergeOverride(childAggregate);
         }
     }
     catch
     {
         this.error = AggregateValue.Error;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates an <see cref="InternalServerError"/> from an exception.
        /// </summary>
        /// <param name="exception">An exception.</param>
        /// <param name="uniqueId">The ID of the request that caused this error. This should not be null,
        /// but if it is, the generated error will contain an empty string.</param>
        /// <param name="includeDetails">
        /// <c>true</c> if debugging details should be included; <c>false</c>
        /// to omit this potentailly sensitive information
        /// </param>
        /// <returns>An InternalServerError representing the exception.</returns>
        public static InternalServerError MakeInternalServerError(Exception exception, string uniqueId, bool includeDetails)
        {
            var internalServerError = new InternalServerError
            {
                error_code = (int)ErrorCode.InternalServerError,
                unique_id  = uniqueId ?? ""
            };

            if (includeDetails && exception != null)
            {
                internalServerError.message            = InternalErrorMessage + ": " + exception.Message;
                internalServerError.server_stack_trace = exception.StackTrace;

                var aggEx = exception as AggregateException;
                if (aggEx != null)
                {
                    var aggregateError = new AggregateError
                    {
                        error_code   = (int)ErrorCode.MultipleErrorsOccured,
                        message      = "One or more errors occured",
                        inner_errors = new List <IBonded <Error> >(aggEx.InnerExceptions.Count)
                    };

                    foreach (var innerException in aggEx.InnerExceptions)
                    {
                        var innerError = MakeInternalServerError(innerException, uniqueId, includeDetails);
                        aggregateError.inner_errors.Add(new Bonded <InternalServerError>(innerError));
                    }

                    internalServerError.inner_error = new Bonded <AggregateError>(aggregateError);
                }
                else if (exception.InnerException != null)
                {
                    var innerError = MakeInternalServerError(exception.InnerException, uniqueId, includeDetails);
                    internalServerError.inner_error = new Bonded <InternalServerError>(innerError);
                }
            }
            else
            {
                internalServerError.message = InternalErrorMessage;
            }

            return(internalServerError);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates an <see cref="InternalServerError"/> from an exception.
        /// </summary>
        /// <param name="exception">An exception.</param>
        /// <param name="uniqueId">The ID of the request that caused this error. This should not be null,
        /// but if it is, the generated error will contain an empty string.</param>
        /// <param name="includeDetails">
        /// <c>true</c> if debugging details should be included; <c>false</c>
        /// to omit this potentailly sensitive information
        /// </param>
        /// <returns>An InternalServerError representing the exception.</returns>
        public static InternalServerError MakeInternalServerError(Exception exception, string uniqueId, bool includeDetails)
        {
            var internalServerError = new InternalServerError
            {
                error_code = (int)ErrorCode.INTERNAL_SERVER_ERROR,
                unique_id = uniqueId ?? string.Empty
            };

            if (includeDetails && exception != null)
            {
                internalServerError.message = InternalErrorMessage + ": " + exception.Message;
                internalServerError.server_stack_trace = exception.StackTrace;

                var aggEx = exception as AggregateException;
                if (aggEx != null)
                {
                    var aggregateError = new AggregateError
                    {
                        error_code = (int) ErrorCode.MULTIPLE_ERRORS_OCCURRED,
                        message = "One or more errors occured",
                        inner_errors = new List<IBonded<Error>>(aggEx.InnerExceptions.Count)
                    };

                    foreach (var innerException in aggEx.InnerExceptions)
                    {
                        var innerError = MakeInternalServerError(innerException, uniqueId, includeDetails);
                        aggregateError.inner_errors.Add(new Bonded<InternalServerError>(innerError));
                    }

                    internalServerError.inner_error = new Bonded<AggregateError>(aggregateError);
                }
                else if (exception.InnerException != null)
                {
                    var innerError = MakeInternalServerError(exception.InnerException, uniqueId, includeDetails);
                    internalServerError.inner_error = new Bonded<InternalServerError>(innerError);
                }
            }
            else
            {
                internalServerError.message = InternalErrorMessage;
            }

            return internalServerError;
        }
Exemplo n.º 10
0
 internal void RaiseError()
 {
     this.error = AggregateValue.Error;
 }