-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInternalError.swift
More file actions
74 lines (63 loc) · 2.3 KB
/
InternalError.swift
File metadata and controls
74 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Ably
/// An error thrown by the internals of the Chat SDK.
///
/// This was originally created to represent any of the various internal types that existed at the time of converting the public API of the SDK to throw ARTErrorInfo. We may rethink this when we do a broader rethink of the errors thrown by the SDK in https://github.com/ably/ably-chat-swift/issues/32. For now, feel free to introduce further internal error types and add them to the `Other` enum.
internal enum InternalError: Error {
case errorInfo(ARTErrorInfo)
case other(Other)
internal enum Other {
case chatAPIChatError(ChatAPI.ChatError)
case headersValueJSONDecodingError(HeadersValue.JSONDecodingError)
case jsonValueDecodingError(JSONValueDecodingError)
case paginatedResultError(PaginatedResultError)
case messagesError(DefaultMessages.MessagesError)
}
/// Returns the error that this should be converted to when exposed via the SDK's public API.
internal func toARTErrorInfo() -> ARTErrorInfo {
switch self {
case let .errorInfo(errorInfo):
errorInfo
case let .other(other):
.init(chatError: .nonErrorInfoInternalError(other))
}
}
// Useful for logging
internal var message: String {
toARTErrorInfo().message
}
}
extension InternalError: Equatable {
internal static func == (lhs: InternalError, rhs: InternalError) -> Bool {
lhs.toARTErrorInfo() == rhs.toARTErrorInfo()
}
}
internal extension ARTErrorInfo {
func toInternalError() -> InternalError {
.errorInfo(self)
}
}
internal extension ChatAPI.ChatError {
func toInternalError() -> InternalError {
.other(.chatAPIChatError(self))
}
}
internal extension HeadersValue.JSONDecodingError {
func toInternalError() -> InternalError {
.other(.headersValueJSONDecodingError(self))
}
}
internal extension JSONValueDecodingError {
func toInternalError() -> InternalError {
.other(.jsonValueDecodingError(self))
}
}
internal extension PaginatedResultError {
func toInternalError() -> InternalError {
.other(.paginatedResultError(self))
}
}
internal extension DefaultMessages.MessagesError {
func toInternalError() -> InternalError {
.other(.messagesError(self))
}
}