Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(asgardeo-android-core-auth-direct): Improve error messages in the Asgardeo-Android SDK #53

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The Asgardeo Android SDK is developed using Kotlin and is built using the Androi
```
This will publish the SDK to the local Maven repository. You can find the SDK in the following location.
```
~/.m2/repository/org/io/asgardeo/asgardeo-android/<MAIN_VERSION>
~/.m2/repository/io/asgardeo/asgardeo-android/<MAIN_VERSION>
```
You can also find the SDK in the `External Libraries` section in the project view of Android Studio.
3. Note the version of the SDK that you have released to the local Maven repository. You can find the version in the `gradle.properties` file in the root of the SDK project, in the variable `MAIN_VERSION`.
Expand Down Expand Up @@ -99,6 +99,10 @@ You can test the changes by running any Android application and including the SD
}
}
```
> [!TIP]
> There are some reports that the `mavenLocal()` repository is not being resolved in the `settings.gradle` file. To
> resolve this issue, please refer to this StackOverflow [thread](https://stackoverflow.com/questions/32107205/gradle-does-not-use-the-maven-local-repository-for-a-new-dependency).


3. Build and run the sample application using the above mentioned [documentation](https://github.com/wso2/samples-is/blob/master/petcare-sample/b2c/mobile-app/petcare-with-sdk/README.md).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ internal class FlowManagerImpl private constructor() : FlowManager {
* TODO: Need to check additional check to flowid to check if the flow is the same as the current flow
*/
override fun manageStateOfAuthorizeFlow(responseObject: JsonNode): AuthenticationFlow {
// Get the messages from the response object
val messages: JsonNode? = responseObject.get("nextStep")?.get("messages")

return when (responseObject.get("flowStatus").asText()) {
/**
* TODO: Add exact error message returned from Asgardeo to the FlowManagerException
Expand All @@ -112,7 +115,8 @@ internal class FlowManagerImpl private constructor() : FlowManager {
*/
FlowStatus.FAIL_INCOMPLETE.flowStatus -> {
throw FlowManagerException(
FlowManagerException.AUTHENTICATION_NOT_COMPLETED
message = FlowManagerException.AUTHENTICATION_NOT_COMPLETED,
messages = if (messages != null) arrayListOf(messages) else arrayListOf()
)
}

Expand All @@ -126,7 +130,8 @@ internal class FlowManagerImpl private constructor() : FlowManager {

else -> {
throw FlowManagerException(
FlowManagerException.AUTHENTICATION_NOT_COMPLETED_UNKNOWN
message = FlowManagerException.AUTHENTICATION_NOT_COMPLETED_UNKNOWN,
messages = if (messages != null) arrayListOf(messages) else arrayListOf()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import io.asgardeo.android.core_auth_direct.core.managers.flow.FlowManager
* Exception to be thrown to the exception related to [FlowManager]
*/
class FlowManagerException(
override val message: String?
override val message: String?,
val messages: ArrayList<Any> = arrayListOf()
) : Exception(message) {
companion object {
/**
Expand Down
8 changes: 6 additions & 2 deletions docs/website/android/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ is AuthenticationState.Error -> {

Also if you want to show an error message in the TextFields, you have to navigate to the login component and show the error message.

> [!NOTE]
> There is an issue in the SDK that the exact error message provided from Asgardeo is not correctly passed to the `FlowManagerException`. This is a known issue that is tracked in the [GitHub repository](https://github.com/asgardeo/mobile-ui-sdks/issues/44).
To view the specific error message, you can use the the `messages` property of the `FlowManagerException` as shown below:

```kotlin
val messages: ArrayList<any> = (it.throwable as FlowManagerException).messages
```
This will return an array of error messages that is returned by Asgardeo, explaining the error in detail.

### Authenticator Not Found Error

Expand Down
Loading