|
14 | 14 |
|
15 | 15 | package google.registry.mosapi; |
16 | 16 |
|
| 17 | +import static com.google.common.base.Preconditions.checkArgument; |
| 18 | + |
| 19 | +import com.google.common.base.Throwables; |
17 | 20 | import google.registry.config.RegistryConfig.Config; |
18 | 21 | import google.registry.mosapi.MosApiException.MosApiAuthorizationException; |
19 | 22 | import jakarta.inject.Inject; |
@@ -43,9 +46,9 @@ public MosApiClient( |
43 | 46 | this.httpClient = httpClient; |
44 | 47 | // Pre-calculate base URL and validate it to fail fast on bad config |
45 | 48 | String fullUrl = String.format("%s/%s", mosapiUrl, entityType); |
46 | | - if (HttpUrl.parse(fullUrl) == null) { |
47 | | - throw new IllegalArgumentException("Invalid MoSAPI Service URL configuration: " + fullUrl); |
48 | | - } |
| 49 | + checkArgument( |
| 50 | + HttpUrl.parse(fullUrl) != null, "Invalid MoSAPI Service URL configuration: %s", fullUrl); |
| 51 | + |
49 | 52 | this.baseUrl = fullUrl; |
50 | 53 | } |
51 | 54 |
|
@@ -73,9 +76,7 @@ public Response sendGetRequest( |
73 | 76 | return checkResponseForAuthError(response); |
74 | 77 | } catch (RuntimeException | IOException e) { |
75 | 78 | // Check if it's the specific authorization exception (re-thrown or caught here) |
76 | | - if (e instanceof MosApiAuthorizationException) { |
77 | | - throw (MosApiAuthorizationException) e; |
78 | | - } |
| 79 | + Throwables.throwIfInstanceOf(e, MosApiAuthorizationException.class); |
79 | 80 | // Otherwise, treat as a generic connection/API error |
80 | 81 | throw new MosApiException("Error during GET request to " + url, e); |
81 | 82 | } |
@@ -114,9 +115,7 @@ public Response sendPostRequest( |
114 | 115 | return checkResponseForAuthError(response); |
115 | 116 | } catch (RuntimeException | IOException e) { |
116 | 117 | // Check if it's the specific authorization exception (re-thrown or caught here) |
117 | | - if (e instanceof MosApiAuthorizationException) { |
118 | | - throw (MosApiAuthorizationException) e; |
119 | | - } |
| 118 | + Throwables.throwIfInstanceOf(e, MosApiAuthorizationException.class); |
120 | 119 | // Otherwise, treat as a generic connection/API error |
121 | 120 | throw new MosApiException("Error during POST request to " + url, e); |
122 | 121 | } |
|
0 commit comments