Error Handling

How to Read Localized Error Messages

AccountManager.signOut() { error in
    guard error == nil else {
        print("Error: \(error.localizedDescription)")
    }
}

Use the error.localizedDescription property to get the localized error message from NSError.

How to Read the Debug Error Message

AccountManager.signOut() { error in
    guard error == nil else {
        print("Error: \(error.debugDescription)")
    }
}

Use the error.debugDescription property to get the debug error message from NSError.

How to Read the Error Reason

AccountManager.signOut() { error in
    guard error == nil else {
        print("Error: \(error.serverResponseErrorReason)")
    }
}

Use the error.serverResponseErrorReason property to get the error reason from NSError.

Note: If the error is not generated by the server, it is generated by the SDK. As a result, error.serverResponseErrorReason is nil.

How to Read the Server Response Error Status

AccountManager.signOut() { error in
    guard error == nil else {
        print("Error: \(error.serverResponseErrorStatus)") // e.g. "INVALID_INPUT"
    }
}

Use the error.serverResponseErrorStatus property to get the error status from NSError.

Note: If the error is not generated by the server, it is generated by the SDK. As a result, error.serverResponseErrorReason is nil.

How to Read the HTTP Response Status Code

AccountManager.signOut() { error in
    guard error == nil else {
        print("Error: \(error.httpResponseStatusCode)")            // e.g. 503 (Service Unavailable)
    }
}

Use the error.httpResponseStatusCode property to get the HTTP response status code from NSError.

Note: When the error is not generated by the server, it is generated by the SDK. As a result, error.httpResponseStatusCode is -1.