|
36 | 36 | import com.sap.cloud.security.config.ClientIdentity; |
37 | 37 | import com.sap.cloud.security.token.Token; |
38 | 38 | import com.sap.cloud.security.xsuaa.client.DefaultOAuth2TokenService; |
| 39 | +import com.sap.cloud.security.xsuaa.client.OAuth2ServiceException; |
39 | 40 | import com.sap.cloud.security.xsuaa.client.OAuth2TokenResponse; |
40 | 41 | import com.sap.cloud.security.xsuaa.client.OAuth2TokenService; |
41 | 42 |
|
@@ -193,12 +194,16 @@ private OAuth2TokenResponse executeClientCredentialsFlow( @Nullable final Tenant |
193 | 194 | .getOrElseThrow(e -> buildException(e, tenant)); |
194 | 195 | } |
195 | 196 |
|
196 | | - private TokenRequestFailedException buildException(@Nonnull final Throwable e, @Nullable final Tenant tenant ) |
| 197 | + private TokenRequestFailedException buildException( @Nonnull final Throwable e, @Nullable final Tenant tenant ) |
197 | 198 | { |
198 | 199 | String msg = "Failed to resolve access token."; |
199 | | - // In case where tenant is subscriber, and we get 401 error, add hint to error message. |
200 | | - if( e.getMessage().contains("Http status code 401") && tenant != null ) { |
201 | | - msg += " This might be due to missing or wrongly set up dependencies in your SaaS registry."; |
| 200 | + // In case where tenant is not the provider tenant, and we get 401 error, add hint to error message. |
| 201 | + if( e instanceof OAuth2ServiceException |
| 202 | + && ((OAuth2ServiceException) e).getHttpStatusCode().equals(401) |
| 203 | + && tenant != null ) { |
| 204 | + msg += |
| 205 | + " In case you are accessing a multi-tenant BTP service, ensure that the service instance is declared as dependency " |
| 206 | + + "to SaaS Provisioning Service or Subscription Manager (SMS) and subscribed for the current tenant."; |
202 | 207 | } |
203 | 208 | return new TokenRequestFailedException(msg, e); |
204 | 209 | } |
|
0 commit comments