@@ -153,13 +153,42 @@ enum SecretType {
153153 * Generic method for making a request to the provided URL with the provided post data. Returns an
154154 * instance of the provided generic JSON class or an error message with the provided error.
155155 */
156- private <T > CompletableFuture <T > makeRequestAndParseFailure (GenericUrl url ,
157- Map <String , Object > postData , Class <T > jsonType , String errorMessage ) {
156+ private <T extends NullParsingValidator > CompletableFuture <T > makeRequestAndParseFailure (
157+ GenericUrl url , Map <String , Object > postData , Class <T > jsonType , String errorMessage ) {
158158 return CompletableFuture .supplyAsync (() -> {
159159 try {
160160 HttpResponse resp = this .getApiRequest (postData , url ).execute ();
161161 if (resp .isSuccessStatusCode ()) {
162- return resp .parseAs (jsonType );
162+ T parsed = resp .parseAs (jsonType );
163+ parsed .ensureNoNullsOrThrow ();
164+ return parsed ;
165+ }
166+ throw parseFailureFromRequest (resp );
167+ } catch (Exception cause ) {
168+ if (cause instanceof TenantSecurityException ) {
169+ throw new CompletionException (cause );
170+ } else if (cause instanceof IllegalArgumentException ) {
171+ throw new CompletionException (new TspServiceException (
172+ TenantSecurityErrorCodes .UNKNOWN_ERROR , 0 , errorMessage , cause ));
173+ }
174+ throw new CompletionException (new TspServiceException (
175+ TenantSecurityErrorCodes .UNABLE_TO_MAKE_REQUEST , 0 , errorMessage , cause ));
176+ }
177+ }, webRequestExecutor );
178+ }
179+
180+ /**
181+ * Overload for generic method for making a request to the provided URL with the provided post
182+ * data. Returns a CompletableFuture<Void> because it does not try to parse a successful result.
183+ * In the case of an error, it does try to parse the provided error.
184+ */
185+ private CompletableFuture <Void > makeRequestAndParseFailure (GenericUrl url ,
186+ Map <String , Object > postData , String errorMessage ) {
187+ return CompletableFuture .supplyAsync (() -> {
188+ try {
189+ HttpResponse resp = this .getApiRequest (postData , url ).execute ();
190+ if (resp .isSuccessStatusCode ()) {
191+ return null ;
163192 }
164193 throw parseFailureFromRequest (resp );
165194 } catch (Exception cause ) {
@@ -261,7 +290,7 @@ CompletableFuture<Void> logSecurityEvent(SecurityEvent event, EventMetadata meta
261290 String error = String .format (
262291 "Unable to make request to Tenant Security Proxy security event endpoint. Endpoint requested: %s" ,
263292 this .securityEventEndpoint );
264- return this .makeRequestAndParseFailure (this .securityEventEndpoint , postData , Void . class , error );
293+ return this .makeRequestAndParseFailure (this .securityEventEndpoint , postData , error );
265294 }
266295
267296 /**
0 commit comments