Created
March 27, 2017 16:41
-
-
Save JohnSundell/efc05e4e49360e98d0e064f22d565da7 to your computer and use it in GitHub Desktop.
Code sample #2 from https://medium.com/@johnsundell/providing-a-unified-swift-error-api-3642cd3173f0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loadSearchData(matching query: String) throws -> Data { | |
let urlString = "https://my.api.com/search?q=\(query)" | |
guard let url = URL(string: urlString) else { | |
throw SearchError.invalidQuery(query) | |
} | |
do { | |
return try Data(contentsOf: url) | |
} catch { | |
throw SearchError.dataLoadingFailed(url) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment