Пример #1
0
        public static FulcrumException ToFulcrumException(FulcrumError error)
        {
            if (error == null)
            {
                return(null);
            }
            FulcrumException exception;

            switch (error.TypeId)
            {
            case BusinessRuleException.ExceptionTypeId:
                exception = new BusinessRuleException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case ConflictException.ExceptionTypeId:
                exception = new ConflictException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case ServerContractException.ExceptionTypeId:
                exception = new ServerContractException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case NotFoundException.ExceptionTypeId:
                exception = new NotFoundException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case UnauthorizedException.ExceptionTypeId:
                exception = new UnauthorizedException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case AssertionFailedException.ExceptionTypeId:
                exception = new AssertionFailedException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case NotImplementedException.ExceptionTypeId:
                exception = new NotImplementedException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            case TryAgainException.ExceptionTypeId:
                exception = new TryAgainException(error.TechnicalMessage, ToFulcrumException(error.InnerError));
                break;

            default:
                exception = null;
                break;
            }
            if (exception == null)
            {
                var message = $"The TypeId ({error.TypeId}) was not recognized: {error.ToJsonString(Formatting.Indented)}";
                return(new AssertionFailedException(message, ToFulcrumException(error.InnerError)));
            }
            exception.CopyFrom(error);
            return(exception);
        }
Пример #2
0
        private static void ValidateStatusCode(HttpStatusCode statusCode, FulcrumError error)
        {
            var expectedStatusCode = ToHttpStatusCode(error);

            if (expectedStatusCode == null)
            {
                throw new AssertionFailedException(
                          $"The TypeId of the content could not be converted to an HTTP status code: {error.ToJsonString(Formatting.Indented)}.");
            }
            if (expectedStatusCode != statusCode)
            {
                throw new AssertionFailedException(
                          $"The HTTP error response had status code {statusCode}, but was expected to have {expectedStatusCode.Value}, due to the TypeId in the content: \"{error.ToJsonString(Formatting.Indented)}");
            }
        }