mirror of
https://github.com/mas-cli/mas
synced 2024-11-21 19:23:01 +00:00
Merge pull request #550 from rgoldberg/536-output-responses-unparsable-as-json
Output to stderr responses from Apple endpoints that are unparsable as JSON
This commit is contained in:
commit
1bebde9e4a
3 changed files with 14 additions and 6 deletions
|
@ -108,7 +108,7 @@ class MasStoreSearch: StoreSearch {
|
|||
do {
|
||||
return try JSONDecoder().decode(SearchResultList.self, from: data).results
|
||||
} catch {
|
||||
throw MASError.jsonParsing(error: error as NSError)
|
||||
throw MASError.jsonParsing(data: data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public enum MASError: Error, Equatable {
|
|||
case uninstallFailed
|
||||
|
||||
case noData
|
||||
case jsonParsing(error: NSError?)
|
||||
case jsonParsing(data: Data?)
|
||||
}
|
||||
|
||||
// MARK: - CustomStringConvertible
|
||||
|
@ -93,8 +93,16 @@ extension MASError: CustomStringConvertible {
|
|||
case .noData:
|
||||
return "Service did not return data"
|
||||
|
||||
case .jsonParsing:
|
||||
return "Unable to parse response JSON"
|
||||
case .jsonParsing(let data):
|
||||
if let data {
|
||||
if let unparsable = String(data: data, encoding: .utf8) {
|
||||
return "Unable to parse response as JSON: \n\(unparsable)"
|
||||
} else {
|
||||
return "Received defective response"
|
||||
}
|
||||
} else {
|
||||
return "Received empty response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ class MASErrorTestCase: XCTestCase {
|
|||
}
|
||||
|
||||
func testJsonParsing() {
|
||||
error = .jsonParsing(error: nil)
|
||||
XCTAssertEqual(error.description, "Unable to parse response JSON")
|
||||
error = .jsonParsing(data: nil)
|
||||
XCTAssertEqual(error.description, "Received empty response")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue