55import java .time .Duration ;
66import java .util .HashMap ;
77import java .util .Map ;
8- import java .util .Objects ;
98import java .util .concurrent .CompletableFuture ;
109import java .util .concurrent .TimeUnit ;
1110import java .util .logging .Logger ;
1716import static com .contentstack .cms .core .Util .API_KEY ;
1817import static com .contentstack .cms .core .Util .AUTHORIZATION ;
1918import static com .contentstack .cms .core .Util .BRANCH ;
20- import static com .contentstack .cms .core .Util .ILLEGAL_USER ;
21- import static com .contentstack .cms .core .Util .PLEASE_LOGIN ;
2219import com .contentstack .cms .models .Error ;
2320import com .contentstack .cms .models .LoginDetails ;
2421import com .contentstack .cms .models .OAuthConfig ;
@@ -99,7 +96,7 @@ public class Contentstack {
9996 */
10097 public User user () {
10198 if (!isOAuthConfigured () && this .authtoken == null ) {
102- throw new IllegalStateException ("Please login or configure OAuth to access user" );
99+ throw new IllegalStateException (Util . OAUTH_LOGIN_REQUIRED + " user" );
103100 }
104101 user = new User (this .instance );
105102 return user ;
@@ -293,7 +290,7 @@ Response<ResponseBody> logoutWithAuthtoken(String authtoken) throws IOException
293290 */
294291 public Organization organization () {
295292 if (!isOAuthConfigured () && this .authtoken == null ) {
296- throw new IllegalStateException ("Please login or configure OAuth to access organization" );
293+ throw new IllegalStateException (Util . OAUTH_LOGIN_REQUIRED + " organization" );
297294 }
298295
299296 // If using OAuth, get organization from tokens
@@ -328,10 +325,10 @@ public Organization organization() {
328325 */
329326 public Organization organization (@ NotNull String organizationUid ) {
330327 if (!isOAuthConfigured () && this .authtoken == null ) {
331- throw new IllegalStateException ("Please login or configure OAuth to access organization" );
328+ throw new IllegalStateException (Util . OAUTH_LOGIN_REQUIRED + " organization" );
332329 }
333330 if (organizationUid .isEmpty ()) {
334- throw new IllegalStateException ("organizationUid can not be empty" );
331+ throw new IllegalStateException (Util . OAUTH_ORG_EMPTY );
335332 }
336333 return new Organization (this .instance , organizationUid );
337334 }
@@ -355,7 +352,7 @@ public Organization organization(@NotNull String organizationUid) {
355352 */
356353 public Stack stack () {
357354 if (!isOAuthConfigured () && this .authtoken == null ) {
358- throw new IllegalStateException ("Please login or configure OAuth to access stack" );
355+ throw new IllegalStateException (Util . OAUTH_LOGIN_REQUIRED + " stack" );
359356 }
360357 return new Stack (this .instance );
361358 }
@@ -380,7 +377,7 @@ public Stack stack() {
380377 */
381378 public Stack stack (@ NotNull Map <String , Object > header ) {
382379 if (!isOAuthConfigured () && this .authtoken == null && !header .containsKey (AUTHORIZATION )) {
383- throw new IllegalStateException ("Please login or configure OAuth to access stack" );
380+ throw new IllegalStateException (Util . OAUTH_LOGIN_REQUIRED + " stack" );
384381 }
385382 return new Stack (this .instance , header );
386383 }
@@ -476,7 +473,7 @@ public Stack stack(@NotNull String apiKey, @NotNull String managementToken, @Not
476473 */
477474 public String getOAuthAuthorizationUrl () {
478475 if (!isOAuthConfigured ()) {
479- throw new IllegalStateException ("OAuth is not configured. Use Builder.setOAuth() or Builder.setOAuthWithPKCE()" );
476+ throw new IllegalStateException (Util . OAUTH_CONFIG_MISSING );
480477 }
481478 return oauthHandler .authorize ();
482479 }
@@ -489,7 +486,7 @@ public String getOAuthAuthorizationUrl() {
489486 */
490487 public CompletableFuture <OAuthTokens > exchangeOAuthCode (String code ) {
491488 if (!isOAuthConfigured ()) {
492- throw new IllegalStateException ("OAuth is not configured. Use Builder.setOAuth() or Builder.setOAuthWithPKCE()" );
489+ throw new IllegalStateException (Util . OAUTH_CONFIG_MISSING );
493490 }
494491 return oauthHandler .exchangeCodeForToken (code );
495492 }
@@ -501,7 +498,7 @@ public CompletableFuture<OAuthTokens> exchangeOAuthCode(String code) {
501498 */
502499 public CompletableFuture <OAuthTokens > refreshOAuthToken () {
503500 if (!isOAuthConfigured ()) {
504- throw new IllegalStateException ("OAuth is not configured. Use Builder.setOAuth() or Builder.setOAuthWithPKCE()" );
501+ throw new IllegalStateException (Util . OAUTH_CONFIG_MISSING );
505502 }
506503 return oauthHandler .refreshAccessToken ();
507504 }
@@ -545,7 +542,7 @@ public OAuthHandler getOAuthHandler() {
545542 */
546543 public CompletableFuture <Void > oauthLogout (boolean revokeAuthorization ) {
547544 if (!isOAuthConfigured ()) {
548- throw new IllegalStateException ("OAuth is not configured. Use Builder.setOAuth() or Builder.setOAuthWithPKCE()" );
545+ throw new IllegalStateException (Util . OAUTH_CONFIG_MISSING );
549546 }
550547 return oauthHandler .logout (revokeAuthorization );
551548 }
0 commit comments