Skip to content

Commit 9365c30

Browse files
md-waldronKadi Kraman
authored andcommitted
More detailed error messages when available in Android (#323)
* More detailed error messages when available in Android * More detailed error messages when available in Android
1 parent 3cb01d4 commit 9365c30

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

android/src/main/java/com/rnappauth/RNAppAuthModule.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void onFetchConfigurationCompleted(
187187
@Nullable AuthorizationServiceConfiguration fetchedConfiguration,
188188
@Nullable AuthorizationException ex) {
189189
if (ex != null) {
190-
promise.reject("Failed to fetch configuration", ex.errorDescription);
190+
promise.reject("Failed to fetch configuration", getErrorMessage(ex));
191191
return;
192192
}
193193

@@ -269,7 +269,7 @@ public void onFetchConfigurationCompleted(
269269
@Nullable AuthorizationServiceConfiguration fetchedConfiguration,
270270
@Nullable AuthorizationException ex) {
271271
if (ex != null) {
272-
promise.reject("Failed to fetch configuration", ex.errorDescription);
272+
promise.reject("Failed to fetch configuration", getErrorMessage(ex));
273273
return;
274274
}
275275

@@ -303,7 +303,7 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
303303
final AuthorizationResponse response = AuthorizationResponse.fromIntent(data);
304304
AuthorizationException exception = AuthorizationException.fromIntent(data);
305305
if (exception != null) {
306-
promise.reject("Failed to authenticate", exception.errorDescription);
306+
promise.reject("Failed to authenticate", getErrorMessage(exception));
307307
return;
308308
}
309309

@@ -325,7 +325,7 @@ public void onTokenRequestCompleted(
325325
WritableMap map = TokenResponseFactory.tokenResponseToMap(resp, response);
326326
authorizePromise.resolve(map);
327327
} else {
328-
promise.reject("Failed exchange token", ex.errorDescription);
328+
promise.reject("Failed exchange token", getErrorMessage(ex));
329329
}
330330
}
331331
};
@@ -464,7 +464,7 @@ public void onTokenRequestCompleted(@Nullable TokenResponse response, @Nullable
464464
WritableMap map = TokenResponseFactory.tokenResponseToMap(response);
465465
promise.resolve(map);
466466
} else {
467-
promise.reject("Failed to refresh token", ex.errorDescription);
467+
promise.reject("Failed to refresh token", getErrorMessage(ex));
468468
}
469469
}
470470
};
@@ -500,6 +500,15 @@ private ClientAuthentication getClientAuthentication(String clientSecret, String
500500
return new ClientSecretBasic(clientSecret);
501501
}
502502

503+
/*
504+
* Return error information if it is available
505+
*/
506+
private String getErrorMessage(AuthorizationException ex){
507+
if(ex.errorDescription == null && ex.error != null)
508+
return ex.error;
509+
return ex.errorDescription;
510+
}
511+
503512
/*
504513
* Create a space-delimited string from an array
505514
*/

0 commit comments

Comments
 (0)