Im adding cloud services into my ios app using AWS Amplify API and graphql. This works out of the box, but when testing, I see I will run into trouble if the user of the app loose internet connection.
When testing, I run the code below every second.
func awscreateTodo() {
let todo = Todo(name: "my first todo", description: "todo description")
Amplify.API.mutate(request: .create(todo)) { event in
switch event {
case .success(let result):
switch result {
case .success(let todo):
print("Successfully created the todo: \(todo)")
case .failure(let graphQLError):
print("Failed to create graphql \(graphQLError)")
}
case .failure(let apiError):
print("Failed to create a todo", apiError)
}
}
}
I then disconnect the device from internet. After a while it will throw the following error.
Failed to create a todo APIError: The Internet connection appears to be offline.
Recovery suggestion: The Internet connection appears to be offline.
Caused by:
Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=8, NSUnderlyingError=0x6000002426a0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <3B9BEC23-4B95-4C81-B56F-40C421142923>
How should I handle this issue? Is there a way I can re-connect the service or even catch the error and handle it? If I turn back on the network, it does not help. It will not restart.