@@ -55,25 +55,42 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation {
5555 return
5656 }
5757
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+ }
5966 dataStoreConfiguration. errorHandler ( DataStoreError . api ( apiError, mutationEvent) )
6067 finish ( result: . success( nil ) )
6168 return
6269 }
6370
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
6883 }
6984
7085 guard graphQLErrors. count == 1 else {
7186 log. error ( " Received more than one error response: \( String ( describing: graphQLResponseError) ) " )
87+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
7288 finish ( result: . success( nil ) )
7389 return
7490 }
7591
7692 guard let graphQLError = graphQLErrors. first else {
93+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
7794 finish ( result: . success( nil ) )
7895 return
7996 }
@@ -85,22 +102,26 @@ class ProcessMutationErrorFromCloudOperation: AsynchronousOperation {
85102 let payload = HubPayload ( eventName: HubPayload . EventName. DataStore. conditionalSaveFailed,
86103 data: mutationEvent)
87104 Amplify . Hub. dispatch ( to: . dataStore, payload: payload)
105+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
88106 finish ( result: . success( nil ) )
89107 case . conflictUnhandled:
90108 processConflictUnhandled ( extensions)
91109 case . unauthorized:
92- // TODO: dispatch Hub event
93110 log. debug ( " Unauthorized mutation \( errorType) " )
111+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
94112 finish ( result: . success( nil ) )
95113 case . operationDisabled:
96114 log. debug ( " Operation disabled \( errorType) " )
115+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
97116 finish ( result: . success( nil ) )
98117 case . unknown( let errorType) :
99118 log. debug ( " Unhandled error with errorType \( errorType) " )
119+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
100120 finish ( result: . success( nil ) )
101121 }
102122 } else {
103123 log. debug ( " GraphQLError missing extensions and errorType \( graphQLError) " )
124+ dataStoreConfiguration. errorHandler ( DataStoreError . api ( graphQLResponseError, mutationEvent) )
104125 finish ( result: . success( nil ) )
105126 }
106127 }
0 commit comments