mas/MasKit/Errors/MASError.swift

100 lines
2.5 KiB
Swift
Raw Normal View History

//
// 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
public enum MASError: Error, CustomStringConvertible, Equatable {
2016-09-17 12:58:38 +00:00
case notSignedIn
case signInDisabled
2016-09-25 21:13:23 +00:00
case signInFailed(error: NSError?)
2016-09-17 12:58:38 +00:00
case alreadySignedIn
2016-09-25 21:13:23 +00:00
case purchaseFailed(error: NSError?)
case downloadFailed(error: NSError?)
case noDownloads
case cancelled
2016-09-25 21:13:23 +00:00
case searchFailed
case noSearchResultsFound
case noVendorWebsite
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?)
public var description: String {
2016-09-25 21:13:23 +00:00
switch self {
case .notSignedIn:
return "Not signed in"
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." +
"\nFor more info see: " +
2018-08-12 21:09:58 +00:00
"https://github.com/mas-cli/mas/issues/164"
2019-01-30 06:15:24 +00:00
case let .signInFailed(error):
2016-09-25 21:13:23 +00:00
if let error = error {
return "Sign in failed: \(error.localizedDescription)"
} else {
return "Sign in failed"
}
2016-09-25 21:13:23 +00:00
case .alreadySignedIn:
return "Already signed in"
2019-01-30 06:15:24 +00:00
case let .purchaseFailed(error):
2016-09-25 21:13:23 +00:00
if let error = error {
return "Download request failed: \(error.localizedDescription)"
} else {
return "Download request failed"
}
2019-01-30 06:15:24 +00:00
case let .downloadFailed(error):
2016-09-25 21:13:23 +00:00
if let error = error {
return "Download failed: \(error.localizedDescription)"
} else {
return "Download failed"
}
2016-09-25 21:13:23 +00:00
case .noDownloads:
return "No downloads began"
2016-09-25 21:13:23 +00:00
case .cancelled:
return "Download cancelled"
2016-09-25 21:13:23 +00:00
case .searchFailed:
return "Search failed"
2016-09-25 21:13:23 +00:00
case .noSearchResultsFound:
2018-12-27 21:01:48 +00:00
return "No results found"
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
}
}
}