Skip to content

Commit b5522ee

Browse files
authored
feat(auth): handle errors returned from Social SignIn sessions (#1642)
1 parent 795b512 commit b5522ee

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

AmplifyPlugins/Auth/AWSCognitoAuthPlugin/Dependency/AuthenticationProviderAdapter+SignIn.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,25 @@ extension AuthenticationProviderAdapter {
260260
break
261261
}
262262
}
263+
if self.isErrorCausedByBadRequest(error) {
264+
let errorDescription = error._userInfo?["error"]?
265+
.description.trimmingCharacters(in: .whitespaces) ?? "unknown error"
266+
return AuthError.service(errorDescription,
267+
AuthPluginErrorConstants.hostedUIBadRequestError,
268+
error)
269+
}
263270
let authError = AuthErrorHelper.toAuthError(error)
264271
return authError
265272
}
273+
274+
private func isErrorCausedByBadRequest(_ error: Error?) -> Bool {
275+
if let cognitoAuthError = error as NSError?,
276+
cognitoAuthError.domain == AWSCognitoAuthErrorDomain,
277+
cognitoAuthError.code == AWSCognitoAuthClientErrorType.errorBadRequest.rawValue {
278+
return true
279+
}
280+
return false
281+
}
266282

267283
private class ModalPresentingNavigationController: UINavigationController {
268284

0 commit comments

Comments
 (0)