Reputation: 16430
I've an intent parameter set as dynamic
from the intent definition.
Let's say that the server where I get information for this option is currently down.
It is not clear how to present to users the fact that the options at the moment cannot be retrieved. The completion field where we should return the options also accepts an Error
.
I've filled it with a subclass of Error
and I've also implemented the LocalizedError
protocol for this class... but when I encounter the error from the shortcut App, Apple is just presenting a pop up message that returns a terrible message not localized (but that includes the right Error name).
Here is the code that I'm using...
func provideCarModelOptions(for intent: CarIntent, with completion: @escaping ([String]?, Error?) -> Void) {
if(somethingGoesWrongWithServers()){
completion([],CarError.ServerDown)
}else{
completion(ReturnListOfModels(), nil)
}
}
And this is how I've implementend the CarError
enum
public enum CarError:Error{
case serverDown
case generic
}
extension CarError : LocalizedError{
public var errorDescription: String? {
switch self {
case .serverDown:
return "Server is down"
case .generic:
return "SomethingGoesWrong"
}
}
}
Am I doing anything wrong or Apple is not handling the Errors the right way?
Upvotes: 8
Views: 1119
Reputation: 61
This worked for me to provide localized description:
completion(nil, INIntentError.init(_nsError: NSError(domain: "com.Domain.error", code: 0, userInfo: [NSLocalizedDescriptionKey: "Error Message"])))
Upvotes: 6