Skip to content

Commit 080185c

Browse files
committed
Sources/DataConnectError.swift: add classes to support partial errors.
1 parent 3cb987e commit 080185c

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Sources/DataConnectError.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum DataConnectError: Error {
2424
case grpcNotConfigured
2525

2626
/// failed to decode results from server
27-
case decodeFailed
27+
case decodeFailed(response: AnyDataConnectOperationResponse)
2828

2929
/// Invalid uuid format during encoding / decoding of data
3030
case invalidUUID
@@ -36,5 +36,37 @@ public enum DataConnectError: Error {
3636
case invalidTimestampFormat
3737

3838
/// generic operation execution error
39-
case operationExecutionFailed(messages: String?)
39+
case operationExecutionFailed(response: AnyDataConnectOperationResponse)
4040
}
41+
42+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
43+
public protocol AnyDataConnectOperationResponse {
44+
// JSON string
45+
var data: String? { get }
46+
47+
var errors: [DataConnectOperationErrorInfo] { get }
48+
}
49+
50+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
51+
public struct DataConnectOperationResponse<T> : AnyDataConnectOperationResponse {
52+
// JSON string
53+
public let data: String?
54+
55+
public let errors: [DataConnectOperationErrorInfo]
56+
57+
public let decodedData: T?
58+
}
59+
60+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
61+
public struct DataConnectOperationErrorInfo {
62+
public let message: String
63+
public let path: [PathSegment]
64+
65+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
66+
public enum PathSegment {
67+
case field(String)
68+
case listIndex(Int)
69+
}
70+
71+
}
72+

0 commit comments

Comments
 (0)