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