Error Handling swift

Hi guys!

I’m implementing an app with auth0 with a custom form using the iOS swift SDK. I’m having a problem when I SignUp a user it returns Not Found, then I get the email to verify the email and I can login.
So what I want to do is to handle that Not Found error but I can’t find a way anywhere to get a error code. I’m doing the signup like this:

func signUp(withEmail email: String, username: String?, password: String, connection: String, userMetadata: [String: Any]?, scope: String) {
        self.authentication.signUp(email: email, username: username, password: password, connection: connection, userMetadata: userMetadata, scope: scope).start {
            switch $0 {
            case .failure(let error):
                print("signUp error \(error)")
            case .success(let credentials):
                _ = self.credentialManager.store(credentials: credentials)
                print("Login success")
            }
        }
    }

from the var error I only get the localized description.
Can anyone help to get a message code so I can handle it, please?
Thank you!

Hey there @joao.marques!

Let me ask our SDK team to find out whether there’s a way to access the error code somehow!

I’ll get back to you as soon as they provide me with some info!

Thank you @konrad.sopala. I’ll wait. Otherwise, it’d be nice to have a solution for this problem because I need to pass the message to the user and “Not Found” is not explicit at all. Thank you again!

1 Like

Sure will let you know once I got to know something!

1 Like

Hi, it’s maybe worth to mention 2 things that I found while developing Android in the exact same way for the same app.

  1. the Class that returns the error actually as a code and a description
  2. when signing up a user, it doesn’t give any “Not Found” error. Instead, it sends the email like in iOS and loges in the user directly
    It’s weird that they have different behavior. I’d be good if you could look into that as well.
1 Like

Hi @joao.marques.
In Swift you can cast the error object to something more specific, like an AuthenticationError:

Auth0
    .webAuth()
    .start {
        switch $0 {
        case .failure(let error as AuthenticationError):
            print("Error code: \(error.code), description:\(error.description), info:\(error.info), statusCode:\(error.statusCode)")
        case .failure(let error):
            print("Error: \(error.localizedDescription)")
        case .success(let credentials):
            _ = self.credentialManager.store(credentials: credentials)
            print("Login success")
        }
}
3 Likes

That’s exactly what I was looking for! Thank you very much @nicolas_sabena!

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.