Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit d3267d5

Browse files
committed
added IllegalStateException catch block for incorrectly formatted client id
1 parent 8fc5d64 commit d3267d5

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

app/src/main/java/com/microsoft/graph/connect/ConnectActivity.java

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.microsoft.identity.client.User;
2525

2626
import java.util.List;
27+
import java.util.concurrent.ExecutionException;
2728

2829
/**
2930
* Starting Activity of the app. Handles the connection to Office 365.
@@ -51,29 +52,30 @@ protected void onCreate(Bundle savedInstanceState) {
5152
super.onCreate(savedInstanceState);
5253

5354

54-
Bundle extras = getIntent().getExtras();
55-
setContentView(R.layout.activity_connect);
56-
setTitle(R.string.app_name);
55+
Bundle extras = getIntent().getExtras();
56+
setContentView(R.layout.activity_connect);
57+
setTitle(R.string.app_name);
5758

58-
// set up our views
59-
mConnectButton = (Button) findViewById(R.id.connectButton);
60-
mConnectProgressBar = (ProgressBar) findViewById(R.id.connectProgressBar);
61-
mTitleTextView = (TextView) findViewById(R.id.titleTextView);
62-
mDescriptionTextView = (TextView) findViewById(R.id.descriptionTextView);
59+
// set up our views
60+
mConnectButton = (Button) findViewById(R.id.connectButton);
61+
mConnectProgressBar = (ProgressBar) findViewById(R.id.connectProgressBar);
62+
mTitleTextView = (TextView) findViewById(R.id.titleTextView);
63+
mDescriptionTextView = (TextView) findViewById(R.id.descriptionTextView);
6364

64-
Connect.getInstance().setConnectActivity(this);
65-
// add click listener
66-
mConnectButton.setOnClickListener(new View.OnClickListener() {
67-
@Override
68-
public void onClick(View v) {
69-
showConnectingInProgressUI();
70-
connect();
71-
}
72-
});
65+
Connect.getInstance().setConnectActivity(this);
66+
// add click listener
67+
mConnectButton.setOnClickListener(new View.OnClickListener() {
68+
@Override
69+
public void onClick(View v) {
70+
showConnectingInProgressUI();
71+
connect();
72+
}
73+
});
7374

7475
}
7576

7677
private void connect() {
78+
try {
7779

7880
// The sample app is having the PII enable setting on the MainActivity. Ideally, app should decide to enable Pii or not,
7981
// if it's enabled, it should be the setting when the application is onCreate.
@@ -110,11 +112,22 @@ private void connect() {
110112
}
111113
} catch (MsalClientException e) {
112114
Log.d(TAG, "MSAL Exception Generated while getting users: " + e.toString());
115+
showConnectErrorUI(e.getMessage());
116+
113117

114118
} catch (IndexOutOfBoundsException e) {
115119
Log.d(TAG, "User at this position does not exist: " + e.toString());
120+
showConnectErrorUI(e.getMessage());
121+
116122
}
117123

124+
} catch (IllegalStateException e) {
125+
Log.d(TAG, "MSAL Exception Generated: " + e.toString());
126+
showConnectErrorUI(e.getMessage());
127+
128+
} catch (Exception e) {
129+
showConnectErrorUI();
130+
}
118131

119132
}
120133

@@ -166,6 +179,18 @@ private void showConnectErrorUI() {
166179
R.string.connect_toast_text_error,
167180
Toast.LENGTH_LONG).show();
168181
}
182+
private void showConnectErrorUI(String errorMessage) {
183+
mConnectButton.setVisibility(View.VISIBLE);
184+
mConnectProgressBar.setVisibility(View.GONE);
185+
mTitleTextView.setText(R.string.title_text_error);
186+
mTitleTextView.setVisibility(View.VISIBLE);
187+
mDescriptionTextView.setText(errorMessage);
188+
mDescriptionTextView.setVisibility(View.VISIBLE);
189+
Toast.makeText(
190+
ConnectActivity.this,
191+
R.string.connect_toast_text_error,
192+
Toast.LENGTH_LONG).show();
193+
}
169194

170195
private void showMessage(final String msg) {
171196
getHandler().post(new Runnable() {
@@ -235,10 +260,12 @@ public void onError(MsalException exception) {
235260
// This means errors happened in the sdk itself, could be network, Json parse, etc. Check MsalError.java
236261
// for detailed list of the errors.
237262
showMessage(exception.getMessage());
263+
showConnectErrorUI(exception.getMessage());
238264
} else if (exception instanceof MsalServiceException) {
239265
// This means something is wrong when the sdk is communication to the service, mostly likely it's the client
240266
// configuration.
241267
showMessage(exception.getMessage());
268+
showConnectErrorUI(exception.getMessage());
242269
} else if (exception instanceof MsalUiRequiredException) {
243270
// This explicitly indicates that developer needs to prompt the user, it could be refresh token is expired, revoked
244271
// or user changes the password; or it could be that no token was found in the token cache.

0 commit comments

Comments
 (0)