public void TestIsTokenExpiredError() {
      DfaException exception = null;

      exception = new DfaApiException(TOKEN_EXPIRED_CODE, TOKEN_EXPIRED_MESSAGE);
      Assert.IsTrue(DfaErrorHandler.IsTokenExpiredError(exception));

      exception = new DfaApiException(TOKEN_EXPIRED_CODE, RANDOM_ERROR_MESSAGE);
      Assert.IsFalse(DfaErrorHandler.IsTokenExpiredError(exception));

      exception = new DfaApiException(RANDOM_ERROR_CODE, TOKEN_EXPIRED_MESSAGE);
      Assert.IsFalse(DfaErrorHandler.IsTokenExpiredError(exception));
    }
示例#2
0
 /// <summary>
 /// Determines whether the exception thrown by the server is due to a login
 /// token expiration.
 /// </summary>
 /// <param name="exception">The exception.</param>
 /// <returns>True, if the server exception is a AuthToken invalid error,
 /// false otherwise.</returns>
 public static bool IsTokenExpiredError(Exception exception)
 {
     if (exception is DfaApiException)
     {
         DfaApiException dfaException = (DfaApiException)exception;
         if (dfaException.ErrorCode == TOKEN_EXPIRED_CODE && dfaException.Message.CompareTo(
                 TOKEN_EXPIRED_MESSAGE) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// Gets a custom exception that wraps the SOAP exception thrown
        /// by the server.
        /// </summary>
        /// <param name="exception">SOAPException that was thrown by the server.</param>
        /// <returns>A custom exception object that wraps the SOAP exception.
        /// </returns>
        protected override Exception GetCustomException(SoapException exception)
        {
            string defaultNs = GetDefaultNamespace();

            object apiException = Activator.CreateInstance(Type.GetType(
                                                               this.GetType().Namespace + ".ApiException"));
            XmlNode   faultNode = GetDetailsNode(exception);
            ErrorCode errorCode = null;

            if (faultNode != null)
            {
                errorCode = new ErrorCode();
                foreach (XmlElement xNode in faultNode.SelectNodes("*"))
                {
                    switch (xNode.Name)
                    {
                    case "errorCode":
                        errorCode.Code = int.Parse(xNode.InnerText);
                        break;

                    case "errorMessage":
                        errorCode.Description = xNode.InnerText;
                        break;
                    }
                }
            }
            DfaApiException dfaApiException = new DfaApiException(errorCode, exception.Message,
                                                                  exception);

            if (DfaErrorHandler.IsTokenExpiredError(dfaApiException))
            {
                return(new DfaCredentialsExpiredException(this.Token));
            }
            else
            {
                return(dfaApiException);
            }
        }
    /// <summary>
    /// Gets a custom exception that wraps the SOAP exception thrown
    /// by the server.
    /// </summary>
    /// <param name="ex">SOAPException that was thrown by the server.</param>
    /// <returns>A custom exception object that wraps the SOAP exception.
    /// </returns>
    protected override Exception GetCustomException(SoapException ex) {
      string defaultNs = GetDefaultNamespace();

      object apiException = Activator.CreateInstance(Type.GetType(
          this.GetType().Namespace + ".ApiException"));
      XmlNode faultNode = GetDetailsNode(ex);
      ErrorCode errorCode = null;

      if (faultNode != null) {
        errorCode = new ErrorCode();
        foreach (XmlElement xNode in faultNode.SelectNodes("*")) {
          switch (xNode.Name) {
            case "errorCode":
              errorCode.Code = int.Parse(xNode.InnerText);
              break;

            case "errorMessage":
              errorCode.Description = xNode.InnerText;
              break;
          }
        }
      }
      DfaApiException dfaApiException = new DfaApiException(errorCode, ex.Message, ex);
      if (DfaErrorHandler.IsTokenExpiredError(dfaApiException)) {
        return new DfaCredentialsExpiredException(this.Token);
      } else {
        return dfaApiException;
      }
    }