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
|
|
|
|
|
2018-11-18 02:04:27 +00:00
|
|
|
public enum MASError: Error, CustomStringConvertible, Equatable {
|
2016-09-17 12:58:38 +00:00
|
|
|
case notSignedIn
|
2018-08-11 02:31:03 +00:00
|
|
|
case signInDisabled
|
2016-09-25 21:13:23 +00:00
|
|
|
case signInFailed(error: NSError?)
|
2016-09-17 12:58:38 +00:00
|
|
|
case alreadySignedIn
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case purchaseFailed(error: NSError?)
|
|
|
|
case downloadFailed(error: NSError?)
|
|
|
|
case noDownloads
|
|
|
|
case cancelled
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case searchFailed
|
|
|
|
case noSearchResultsFound
|
2019-01-12 00:11:26 +00:00
|
|
|
case noVendorWebsite
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2018-12-27 21:01:48 +00:00
|
|
|
case notInstalled
|
|
|
|
case uninstallFailed
|
|
|
|
|
2019-01-12 00:11:53 +00:00
|
|
|
case urlEncoding
|
|
|
|
case noData
|
|
|
|
case jsonParsing(error: NSError?)
|
|
|
|
|
2018-10-14 21:35:48 +00:00
|
|
|
public var description: String {
|
2016-09-25 21:13:23 +00:00
|
|
|
switch self {
|
|
|
|
case .notSignedIn:
|
|
|
|
return "Not signed in"
|
2018-08-11 02:31:03 +00:00
|
|
|
|
|
|
|
case .signInDisabled:
|
|
|
|
return "The 'signin' command has been disabled on this macOS version. " +
|
2018-08-12 21:09:58 +00:00
|
|
|
"Please sign into the Mac App Store app manually." +
|
2018-08-11 02:31:03 +00:00
|
|
|
"\nFor more info see: " +
|
2018-08-12 21:09:58 +00:00
|
|
|
"https://github.com/mas-cli/mas/issues/164"
|
2018-08-11 02:31:03 +00:00
|
|
|
|
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"
|
|
|
|
}
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case .alreadySignedIn:
|
|
|
|
return "Already signed in"
|
2018-08-11 02:31:03 +00:00
|
|
|
|
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"
|
|
|
|
}
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case .noDownloads:
|
|
|
|
return "No downloads began"
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case .cancelled:
|
|
|
|
return "Download cancelled"
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case .searchFailed:
|
|
|
|
return "Search failed"
|
2018-08-11 02:31:03 +00:00
|
|
|
|
2016-09-25 21:13:23 +00:00
|
|
|
case .noSearchResultsFound:
|
2018-12-27 21:01:48 +00:00
|
|
|
return "No results found"
|
|
|
|
|
2019-01-12 00:11:26 +00:00
|
|
|
case .noVendorWebsite:
|
|
|
|
return "App does not have a vendor website"
|
|
|
|
|
2018-12-27 21:01:48 +00:00
|
|
|
case .notInstalled:
|
|
|
|
return "Not installed"
|
|
|
|
|
|
|
|
case .uninstallFailed:
|
|
|
|
return "Uninstall failed"
|
2019-01-12 00:11:53 +00:00
|
|
|
|
|
|
|
case .urlEncoding:
|
|
|
|
return "Unable to encode service URL"
|
|
|
|
|
|
|
|
case .noData:
|
|
|
|
return "Service did not return data"
|
|
|
|
|
|
|
|
case .jsonParsing:
|
|
|
|
return "Unable to parse response JSON"
|
2016-09-25 21:13:23 +00:00
|
|
|
}
|
2015-08-21 13:02:36 +00:00
|
|
|
}
|
|
|
|
}
|