@@ -23,9 +23,6 @@ public enum DataConnectError: Error {
2323 /// failed to configure gRPC
2424 case grpcNotConfigured
2525
26- /// failed to decode results from server
27- case decodeFailed( response: AnyOperationFailureResponse )
28-
2926 /// Invalid uuid format during encoding / decoding of data
3027 case invalidUUID
3128
@@ -36,37 +33,45 @@ public enum DataConnectError: Error {
3633 case invalidTimestampFormat
3734
3835 /// generic operation execution error
39- case operationExecutionFailed( response: AnyOperationFailureResponse )
36+ case operationExecutionFailed( messages : String ? , response: OperationFailureResponse )
4037}
4138
39+ // The data and errors sent to us from the backend in its response.
4240@available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
43- public protocol AnyOperationFailureResponse {
44- // JSON string
45- var data : String ? { get }
46-
47- var errors : [ OperationFailureResponseErrorInfo ] { get }
48- }
49-
50- @available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
51- public struct OperationFailureResponse < T> : AnyOperationFailureResponse {
52- // JSON string
53- public let data : String ?
54-
55- public let errors : [ OperationFailureResponseErrorInfo ]
56-
57- public let decodedData : T ?
58-
41+ public struct OperationFailureResponse {
42+ // JSON string whose value is the "data" property provided by the backend in its response
43+ // payload; may be `nil` if the "data" property was not provided in the backend response and/or
44+ // was `null` in the backend response.
45+ public let jsonData : String ?
46+
47+ // The list of errors in the "error" property provided by the backend in its response payload;
48+ // may be empty if the "errors" property was not provided in the backend response and/or was an
49+ // empty list in the backend response.
50+ public let errorInfoList : [ OperationFailureResponseErrorInfo ]
51+
52+ // Returns `jsonData` string decoded into the given type, if decoding was successful when the
53+ // operation was executed. Returns `nil` if `jsonData` is `nil`, if `jsonData` was _not_ able to
54+ // be decoded when the operation was executed, or if the given type is _not_ equal to the `Data`
55+ // type that was used when the operation was executed.
56+ //
57+ // This function does _not_ do the decoding itself, but simply returns the decoded data, if any,
58+ // that was decoded at the time of the operation's execution.
59+ public func decodedData< Data: Decodable > ( asType: Data . Type = Data . self) -> Data ?
5960}
6061
62+ // Information about an error provided by the backend in its response.
6163@available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
6264public struct OperationFailureResponseErrorInfo: Codable {
65+ // The error message.
6366 public let message : String
67+
68+ // The path to the field to which this error applies.
6469 public let path : [ PathSegment ]
6570
6671 @available ( iOS 15 . 0 , macOS 12 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
67- public enum PathSegment : Codable {
72+ public enum PathSegment : Codable , Equatable {
6873 case field( String )
6974 case listIndex( Int )
7075 }
71-
7276}
77+
0 commit comments