Add a little error handling for invalid auth
When changing my api keys, realized I couldn't reauth. Now on a bad auth, we clear the keychain so that we can reauth the next time
This commit is contained in:
parent
bc5e9e9d2b
commit
098d9c3ea6
@ -168,6 +168,7 @@ class FitbitClient {
|
||||
|
||||
|
||||
Alamofire.request(urlString)
|
||||
.validate()
|
||||
.validate(contentType: ["application/json"])
|
||||
.responseJSON(completionHandler: handler)
|
||||
}
|
||||
|
@ -88,8 +88,18 @@ class ViewController: UIViewController {
|
||||
response in FitbitClient.weightResponseHandler(response: response) {
|
||||
fbWeights, error in
|
||||
if let error = error {
|
||||
NSLog("Unable to get weights: \(error)")
|
||||
NSLog("Unable to get weights: \(error.localizedDescription)")
|
||||
if let error = error as? AFError {
|
||||
if let suggestion = error.recoverySuggestion {
|
||||
NSLog("Suggestion to resolve: \(suggestion)")
|
||||
}
|
||||
if error.responseCode == 401 {
|
||||
NSLog("Unauthorized. Clearing credentials")
|
||||
self.client.clearCredential()
|
||||
}
|
||||
}
|
||||
self.outputText.text = "Error getting weights"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user