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.
|
|
|
|
//
|
|
|
|
|
2018-02-11 22:30:59 +00:00
|
|
|
import Foundation
|
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
enum MASError: Error, CustomStringConvertible {
|
2016-09-17 12:58:38 +00:00
|
|
|
case notSignedIn
|
2016-09-25 21:13:23 +00:00
|
|
|
case signInFailed(error: NSError?)
|
2016-09-17 12:58:38 +00:00
|
|
|
case alreadySignedIn
|
2015-08-24 18:44:47 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case purchaseFailed(error: NSError?)
|
|
|
|
case downloadFailed(error: NSError?)
|
|
|
|
case noDownloads
|
|
|
|
case cancelled
|
2015-08-24 18:44:47 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case searchFailed
|
|
|
|
case noSearchResultsFound
|
2015-09-03 23:38:54 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
var description: String {
|
|
|
|
switch self {
|
|
|
|
case .notSignedIn:
|
|
|
|
return "Not signed in"
|
|
|
|
|
2016-10-16 17:08:08 +00:00
|
|
|
case .signInFailed(let error):
|
2016-09-25 21:13:23 +00:00
|
|
|
if let error = error {
|
|
|
|
return "Sign in failed: \(error.localizedDescription)"
|
|
|
|
} else {
|
|
|
|
return "Sign in failed"
|
|
|
|
}
|
|
|
|
|
|
|
|
case .alreadySignedIn:
|
|
|
|
return "Already signed in"
|
|
|
|
|
2016-10-16 17:08:08 +00:00
|
|
|
case .purchaseFailed(let error):
|
2016-09-25 21:13:23 +00:00
|
|
|
if let error = error {
|
|
|
|
return "Download request failed: \(error.localizedDescription)"
|
|
|
|
} else {
|
|
|
|
return "Download request failed"
|
|
|
|
}
|
2016-10-16 17:08:08 +00:00
|
|
|
|
|
|
|
case .downloadFailed(let error):
|
2016-09-25 21:13:23 +00:00
|
|
|
if let error = error {
|
|
|
|
return "Download failed: \(error.localizedDescription)"
|
|
|
|
} else {
|
|
|
|
return "Download failed"
|
|
|
|
}
|
|
|
|
|
|
|
|
case .noDownloads:
|
|
|
|
return "No downloads began"
|
|
|
|
|
|
|
|
case .cancelled:
|
|
|
|
return "Download cancelled"
|
|
|
|
|
|
|
|
case .searchFailed:
|
|
|
|
return "Search failed"
|
|
|
|
|
|
|
|
case .noSearchResultsFound:
|
|
|
|
return "No results found"
|
|
|
|
}
|
2015-08-21 13:02:36 +00:00
|
|
|
}
|
|
|
|
}
|