@@ -55,25 +55,42 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation {
55
55
return
56
56
}
57
57
58
- if let apiError = apiError, isAuthSignedOutError ( apiError: apiError) {
58
+ if let apiError = apiError {
59
+ if isAuthSignedOutError ( apiError: apiError) {
60
+ log. verbose ( " User is signed out, passing error back to the error handler, and removing mutation event. " )
61
+ } else if let underlyingError = apiError. underlyingError {
62
+ log. debug ( " Received APIError: \( apiError. localizedDescription) with underlying error: \( underlyingError. localizedDescription) " )
63
+ } else {
64
+ log. debug ( " Received APIError: \( apiError. localizedDescription) " )
65
+ }
59
66
dataStoreConfiguration. errorHandler ( DataStoreError . api ( apiError, mutationEvent) )
60
67
finish ( result: . success( nil ) )
61
68
return
62
69
}
63
70
64
- guard let graphQLResponseError = graphQLResponseError,
65
- case let . error( graphQLErrors) = graphQLResponseError else {
66
- finish ( result: . success( nil ) )
67
- return
71
+ guard let graphQLResponseError = graphQLResponseError else {
72
+ dataStoreConfiguration. errorHandler (
73
+ DataStoreError . api ( APIError . unknown ( " This is unexpected. Missing APIError and GraphQLError. " , " " ) ,
74
+ mutationEvent) )
75
+ finish ( result: . success( nil ) )
76
+ return
77
+ }
78
+
79
+ guard case let . error( graphQLErrors) = graphQLResponseError else {
80
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
81
+ finish ( result: . success( nil ) )
82
+ return
68
83
}
69
84
70
85
guard graphQLErrors. count == 1 else {
71
86
log. error ( " Received more than one error response: \( String ( describing: graphQLResponseError) ) " )
87
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
72
88
finish ( result: . success( nil ) )
73
89
return
74
90
}
75
91
76
92
guard let graphQLError = graphQLErrors. first else {
93
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
77
94
finish ( result: . success( nil ) )
78
95
return
79
96
}
@@ -85,22 +102,26 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation {
85
102
let payload = HubPayload ( eventName: HubPayload . EventName. DataStore. conditionalSaveFailed,
86
103
data: mutationEvent)
87
104
Amplify . Hub. dispatch ( to: . dataStore, payload: payload)
105
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
88
106
finish ( result: . success( nil ) )
89
107
case . conflictUnhandled:
90
108
processConflictUnhandled ( extensions)
91
109
case . unauthorized:
92
- // TODO: dispatch Hub event
93
110
log. debug ( " Unauthorized mutation \( errorType) " )
111
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
94
112
finish ( result: . success( nil ) )
95
113
case . operationDisabled:
96
114
log. debug ( " Operation disabled \( errorType) " )
115
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
97
116
finish ( result: . success( nil ) )
98
117
case . unknown( let errorType) :
99
118
log. debug ( " Unhandled error with errorType \( errorType) " )
119
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
100
120
finish ( result: . success( nil ) )
101
121
}
102
122
} else {
103
123
log. debug ( " GraphQLError missing extensions and errorType \( graphQLError) " )
124
+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
104
125
finish ( result: . success( nil ) )
105
126
}
106
127
}
0 commit comments