/// <summary>
        /// This class logs errors as they come in.
        /// </summary>
        /// <param name="error"></param>
        public void LogError(string methodName, string objectName, object errorObject)
        {
            // locals
            CustomException exception = null;

            // if this object is
            if (errorObject as CustomException != null)
            {
                // Set exception to errorObject
                exception = (CustomException)errorObject;
            }
            else
            {
                // if error object is an exception
                if (errorObject as Exception != null)
                {
                    // Create error
                    Exception error = (Exception)errorObject;

                    // create exception
                    exception = new UnknownErrorException(methodName, objectName, error);
                }
            }

            try
            {
                // Log Error
                LogError(exception);
            }
            catch
            {
            }
        }
        public void OnException(ExceptionContext context)
        {
            var exception = context.Exception;

            // Catch-all exception handler
            if (!(exception is ApiException))
            {
                var genericMessage = new UnknownErrorException().Message;
                BuildErrorModel(context, genericMessage);
                return;
            }

            // Handle ApiException only
            BuildErrorModel(context, exception.Message);
        }
Beispiel #3
0
        public static EtcdException ProcessException(this FlurlHttpException This)
        {
            if (This.IsTimeoutException())
            {
                return(This.AsTimeoutException());
            }
            if (This.IsInvalidHostException())
            {
                return(This.AsInvalidHostException());
            }
            if (This.IsInvalidRequestException())
            {
                return(This.AsInvalidRequestException());
            }
            if (This.IsBadRequestException())
            {
                return(This.AsBadRequestException());
            }
            if (This.IsServiceUnavailableException())
            {
                return(This.AsServiceUnavailableException());
            }
            if (This.IsHttpConnectionException())
            {
                return(This.AsHttpConnectionException());
            }

            var etcdError = This.GetResponseJson <EtcdError>();

            if (etcdError == null)
            {
                return(new UnknownErrorException(This.Message));
            }

            var message = etcdError.Message;

            etcdError.ErrorCode = etcdError.ErrorCode
                                  ?? (This.GetEtcdErrorCode() ?? EtcdErrorCode.Unknown);

            EtcdException exception;

            // Ugh. The switch from hell.
            switch (etcdError.ErrorCode.Value)
            {
            case EtcdErrorCode.KeyNotFound:
                exception = new KeyNotFoundException(message);
                break;

            case EtcdErrorCode.TestFailed:
                exception = new TestFailedException(message);
                break;

            case EtcdErrorCode.NotFile:
                exception = new NotAFileException(message);
                break;

            case EtcdErrorCode.NoMorePeer:
                exception = new NoMorePeerException(message);
                break;

            case EtcdErrorCode.NotDirectory:
                exception = new NotADirectoryException(message);
                break;

            case EtcdErrorCode.NodeExists:
                exception = new NodeExistsException(message);
                break;

            case EtcdErrorCode.KeyIsPreserved:
                exception = new KeyIsPreservedException(message);
                break;

            case EtcdErrorCode.RootReadOnly:
                exception = new RootIsReadOnlyException(message);
                break;

            case EtcdErrorCode.DirectoryNotEmpty:
                exception = new DirectoryNotEmptyException(message);
                break;

            case EtcdErrorCode.ExistingPeerAddress:
                exception = new ExistingPeerAddressException(message);
                break;

            case EtcdErrorCode.ValueRequired:
                exception = new ValueRequiredException(message);
                break;

            case EtcdErrorCode.PreviousValueRequired:
                exception = new PreviousValueRequiredException(message);
                break;

            case EtcdErrorCode.TtlNotANumber:
                exception = new TtlNotANumberException(message);
                break;

            case EtcdErrorCode.IndexNotANumber:
                exception = new IndexNotANumberException(message);
                break;

            case EtcdErrorCode.ValueOrTtlRequired:
                exception = new ValueOrTtlRequiredException(message);
                break;

            case EtcdErrorCode.TimeoutNotANumber:
                exception = new TimeoutNotANumberException(message);
                break;

            case EtcdErrorCode.NameRequired:
                exception = new NameRequiredException(message);
                break;

            case EtcdErrorCode.IndexOrValueRequired:
                exception = new IndexOrValueRequiredException(message);
                break;

            case EtcdErrorCode.IndexValueMutex:
                exception = new IndexValueMutexException(message);
                break;

            case EtcdErrorCode.InvalidField:
                exception = new InvalidFieldException(message);
                break;

            case EtcdErrorCode.InvalidForm:
                exception = new InvalidFormException(message);
                break;

            case EtcdErrorCode.RaftInternal:
                exception = new RaftInternalException(message);
                break;

            case EtcdErrorCode.LeaderElect:
                exception = new LeaderElectException(message);
                break;

            case EtcdErrorCode.WatcherCleared:
                exception = new WatcherClearedException(message);
                break;

            case EtcdErrorCode.EventIndexCleared:
                exception = new EventIndexClearedException(message);
                break;

            case EtcdErrorCode.StandbyInternal:
                exception = new StandbyInternalException(message);
                break;

            case EtcdErrorCode.InvalidActiveSize:
                exception = new InvalidActiveSizeException(message);
                break;

            case EtcdErrorCode.InvalidRemoveDelay:
                exception = new InvalidRemoveDelayException(message);
                break;

            case EtcdErrorCode.ClientInternal:
                exception = new ClientInternalException(message);
                break;

            default:
                exception = new UnknownErrorException(message);
                break;
            }

            exception.EtcdError = etcdError;
            if (This.Call != null)
            {
                exception.HttpStatusCode = This.Call.HttpStatus;
                exception.RequestUrl     = This.Call.Request.RequestUri.ToString();
                exception.RequestMethod  = This.Call.Request.Method;
            }

            return(exception);
        }
Beispiel #4
0
 /// <summary>
 /// Log an unexpected error when invoking a UDDI service.
 /// </summary>
 /// <param name="unkEx">
 /// The unknown error exception.
 /// </param>
 /// <param name="requestType">
 /// The UDDI request type.
 /// </param>
 /// <param name="siteLocation">
 /// The site location.
 /// </param>
 /// <param name="loggingData">
 /// Additional strings to be logged.
 /// </param>
 public void WriteUddiUnknownError(UnknownErrorException unkEx, string requestType, UddiSiteLocation siteLocation, params string[] loggingData)
 {
     this.WriteUddiError(MessageStrings.UddiUnknown, unkEx, requestType, siteLocation, loggingData);
 }