Skip to content

Commit

Permalink
Add LocalizedError conformance to ConnectError (#327)
Browse files Browse the repository at this point in the history
This improves how error messages are surfaced through `ConnectError`.

Before:
```
(lldb) po response.error?.localizedDescription
▿ Optional<String>
  - some : "The operation couldn’t be completed. (Connect.ConnectError error 1.)"
```

After:
```
(lldb) po response.error?.localizedDescription
▿ Optional<String>
  - some : "The Internet connection appears to be offline."
```

Signed-off-by: Michael Rebello <[email protected]>
  • Loading branch information
rebello95 authored Dec 31, 2024
1 parent 8ec49f5 commit 0820008
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Libraries/Connect/Public/Interfaces/ConnectError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ extension ConnectError: Decodable {
}
}

extension ConnectError: LocalizedError {
public var errorDescription: String? {
return self.message ?? self.exception.map { "internal error: \($0.localizedDescription)" }
}
}

extension ConnectError {
public static func from(
code: Code, headers: Headers?, trailers: Trailers?, source: Data?
Expand Down

0 comments on commit 0820008

Please sign in to comment.