jamesrochabrun / SwiftAnthropic

An open-source Swift package for interacting with Anthropic's public API.
90 stars 29 forks source link

Error Handling #17

Closed elprl closed 4 months ago

elprl commented 4 months ago

Can I suggest updating the APIError so that we can use error.localizedDescription, e.g.:

enum APIError: LocalizedError {
    public var errorDescription: String? { get }
}

rather than creating a new property 'displayDescription' .

elprl commented 4 months ago

Also getting the following concatenation typo: "status code 400Your credit balance is too low to access the Claude API. Please go to Plans & Billing to upgrade or purchase credits."

elprl commented 4 months ago

Here is what I'm doing currently:

extension SwiftAnthropic.APIError: LocalizedError, CustomStringConvertible {
    public var description: String {
        return displayDescription
    }

    /// A localized message describing what error occurred.
    public var errorDescription: String? {
        return displayDescription
    }
}
jamesrochabrun commented 4 months ago

Would you be open to create a pull request for this change? :)

elprl commented 4 months ago

I've edited the file and created the PR, but I've done no testing on this update. #18