2015-08-21 13:02:36 +00:00
|
|
|
//
|
|
|
|
// Error.swift
|
|
|
|
// mas-cli
|
|
|
|
//
|
|
|
|
// Created by Andrew Naylor on 21/08/2015.
|
|
|
|
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2015-08-24 18:44:47 +00:00
|
|
|
public let MASErrorDomain: String = "MASErrorDomain"
|
|
|
|
|
|
|
|
private let MASErrorSource: String = "MASErrorSource"
|
|
|
|
|
|
|
|
public enum MASErrorCode: Int {
|
|
|
|
case NoError
|
|
|
|
case NotSignedIn
|
2015-08-24 18:45:54 +00:00
|
|
|
case PurchaseError
|
2015-09-03 23:13:47 +00:00
|
|
|
case NoDownloads
|
|
|
|
case Cancelled
|
|
|
|
case DownloadFailed
|
2015-08-24 18:44:47 +00:00
|
|
|
|
|
|
|
var exitCode: Int32 {
|
|
|
|
return Int32(self.rawValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MASError: NSError {
|
|
|
|
var masCode: MASErrorCode? {
|
|
|
|
return MASErrorCode(rawValue: code)
|
|
|
|
}
|
|
|
|
|
|
|
|
convenience init(code: MASErrorCode, sourceError: NSError? = nil) {
|
|
|
|
var userInfo: [NSObject: AnyObject] = [:]
|
|
|
|
if let error = sourceError {
|
|
|
|
userInfo[MASErrorSource] = error
|
|
|
|
}
|
|
|
|
self.init(domain: MASErrorDomain, code: code.rawValue, userInfo: userInfo)
|
2015-08-21 13:02:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public func == (lhs: MASError, rhs: MASError) -> Bool {
|
|
|
|
return false
|
|
|
|
}
|