Error

2016-02-27  本文已影响57人  幸运的小强本人

// The Error struct provides a convenience for
// creating custom Alamofire NSErrors.

public struct Error {
  // The domain used for creating all Alamofire errors.
  public static let Domain = "com.alamofire.error"

  // The custom error codes generated by Alamofire.
  public enum Code: Int {
    case InputStreamReadFailed    = -6000
    case OutputStreamWriteFailed  = -6001
    case ContentTypeValidationFailed = -6002
    case StatusCodeValidationFailed = -6003
    case DataSerializationFailed = 6004
    case StringSerializationFailed = 6005
    case JSONSerializationFailed = -6006
    case PropertyListSerializationFailed = -6007
}

/**
  Creates an NSError with the given error code and failure reason
  \- parameter code: The error code
  \- parameter failureReason: the failure reason

  \- returns: An "NSError" with the given error code and failure reason
  */
  public static func errorWithCode(code: Code failureReason: String)-> NSError {
      return errorWithCode(code.rawValue, failureReason: failureReason)
  }

 /**
    Creates an "NSError" with the given error code and failure reason
    \- parameter code: The error code
    \- parameter failureReason: The failure reason

    \- returns: An "NSError" with the given error code and failure reason
*/
public static func errorWithCode(code: Int, failureReason: String)->NSError {
  let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]

    return NSError(domain: Domain, code: code, userInfo:userInfo)
  }
}
上一篇下一篇

猜你喜欢

热点阅读