mas/mas-cli/Error.swift
2016-09-25 22:13:23 +01:00

63 lines
1.7 KiB
Swift

//
// Error.swift
// mas-cli
//
// Created by Andrew Naylor on 21/08/2015.
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
//
enum MASError: Error, CustomStringConvertible {
case notSignedIn
case signInFailed(error: NSError?)
case alreadySignedIn
case purchaseFailed(error: NSError?)
case downloadFailed(error: NSError?)
case noDownloads
case cancelled
case searchFailed
case noSearchResultsFound
var description: String {
switch self {
case .notSignedIn:
return "Not signed in"
case .signInFailed(error: let error):
if let error = error {
return "Sign in failed: \(error.localizedDescription)"
} else {
return "Sign in failed"
}
case .alreadySignedIn:
return "Already signed in"
case .purchaseFailed(error: let error):
if let error = error {
return "Download request failed: \(error.localizedDescription)"
} else {
return "Download request failed"
}
case .downloadFailed(error: let error):
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"
}
}
}