MatterGoal
MatterGoal

Reputation: 16430

Handling Errors with intent parameters and Dynamic options with Siri

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

Answers (1)

youthdancing
youthdancing

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

Related Questions