Skip to content

Commit

Permalink
Don't re-register when update has a network error (#641)
Browse files Browse the repository at this point in the history
Refs #612. This was trying to register on every possible error. A better solution would be to look for specific error responses, but these all come through as 200's from the API calls even if the request fails.

Co-authored-by: Robbie Trencheny <me@robbiet.us>
  • Loading branch information
zacwest and robbiet480 committed Jun 15, 2020
1 parent f6b803f commit 85050e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Shared/API/HAAPI.swift
Expand Up @@ -136,7 +136,12 @@ public class HomeAssistantAPI {
public func Connect() -> Promise<ConfigResponse> {
return firstly {
self.UpdateRegistration()
}.recover { _ -> Promise<MobileAppRegistrationResponse> in
}.recover { error -> Promise<MobileAppRegistrationResponse> in
guard (error as NSError).domain != NSURLErrorDomain else {
Current.Log.info("not re-registering because of network error")
throw error
}

let message = "Failed to update integration; trying to register instead."
Current.clientEventStore.addEvent(ClientEvent(text: message, type: .networkRequest))
return self.Register()
Expand Down

0 comments on commit 85050e0

Please sign in to comment.