Skip to content

Commit 1e837f8

Browse files
millotpapi-clients-bot
and
api-clients-bot
authored
Generated code for commit e4a064f. (#298)
Co-authored-by: Pierre Millot <[email protected]> Co-authored-by: api-clients-bot <[email protected]>
1 parent e4a064f commit 1e837f8

File tree

4 files changed

+788
-662
lines changed

4 files changed

+788
-662
lines changed

clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/ApiCallback.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.algolia;
22

3+
import com.algolia.exceptions.AlgoliaRuntimeException;
34
import java.util.List;
45
import java.util.Map;
56

@@ -17,7 +18,7 @@ public interface ApiCallback<T> {
1718
* @param responseHeaders Headers of the response if available, otherwise it would be null
1819
*/
1920
void onFailure(
20-
ApiException e,
21+
AlgoliaRuntimeException e,
2122
int statusCode,
2223
Map<String, List<String>> responseHeaders
2324
);

clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/ApiClient.java

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.algolia;
22

3+
import com.algolia.exceptions.*;
34
import com.algolia.utils.Requester;
45
import java.io.IOException;
56
import java.io.UnsupportedEncodingException;
@@ -18,7 +19,6 @@ public class ApiClient {
1819
private boolean debugging = false;
1920
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
2021

21-
private String basePath;
2222
private String appId, apiKey;
2323

2424
private DateFormat dateFormat;
@@ -31,7 +31,6 @@ public class ApiClient {
3131
public ApiClient(String appId, String apiKey, Requester requester) {
3232
setUserAgent("OpenAPI-Generator/0.1.0/java");
3333

34-
this.basePath = "https://" + appId + "-1.algolianet.com";
3534
this.appId = appId;
3635
this.apiKey = apiKey;
3736
this.requester = requester;
@@ -330,11 +329,11 @@ public String escapeString(String str) {
330329
* @param response HTTP response
331330
* @param returnType The type of the Java object
332331
* @return The deserialized Java object
333-
* @throws ApiException If fail to deserialize response body, i.e. cannot read response body or
334-
* the Content-Type of the response is not supported.
332+
* @throws AlgoliaRuntimeException If fail to deserialize response body, i.e. cannot read response
333+
* body or the Content-Type of the response is not supported.
335334
*/
336335
public <T> T deserialize(Response response, Type returnType)
337-
throws ApiException {
336+
throws AlgoliaRuntimeException {
338337
if (response == null || returnType == null) {
339338
return null;
340339
}
@@ -344,7 +343,7 @@ public <T> T deserialize(Response response, Type returnType)
344343
try {
345344
return (T) response.body().bytes();
346345
} catch (IOException e) {
347-
throw new ApiException(e);
346+
throw new AlgoliaRuntimeException(e);
348347
}
349348
}
350349

@@ -353,7 +352,7 @@ public <T> T deserialize(Response response, Type returnType)
353352
if (response.body() != null) respBody =
354353
response.body().string(); else respBody = null;
355354
} catch (IOException e) {
356-
throw new ApiException(e);
355+
throw new AlgoliaRuntimeException(e);
357356
}
358357

359358
if (respBody == null || "".equals(respBody)) {
@@ -371,14 +370,12 @@ public <T> T deserialize(Response response, Type returnType)
371370
// Expecting string, return the raw response body.
372371
return (T) respBody;
373372
} else {
374-
throw new ApiException(
373+
throw new AlgoliaApiException(
375374
"Content type \"" +
376375
contentType +
377376
"\" is not supported for type: " +
378377
returnType,
379-
response.code(),
380-
response.headers().toMultimap(),
381-
respBody
378+
response.code()
382379
);
383380
}
384381
}
@@ -390,10 +387,10 @@ public <T> T deserialize(Response response, Type returnType)
390387
* @param obj The Java object
391388
* @param contentType The request Content-Type
392389
* @return The serialized request body
393-
* @throws ApiException If fail to serialize the given object
390+
* @throws AlgoliaRuntimeException If fail to serialize the given object
394391
*/
395392
public RequestBody serialize(Object obj, String contentType)
396-
throws ApiException {
393+
throws AlgoliaRuntimeException {
397394
if (obj instanceof byte[]) {
398395
// Binary (byte array) body parameter support.
399396
return RequestBody.create((byte[]) obj, MediaType.parse(contentType));
@@ -406,7 +403,7 @@ public RequestBody serialize(Object obj, String contentType)
406403
}
407404
return RequestBody.create(content, MediaType.parse(contentType));
408405
} else {
409-
throw new ApiException(
406+
throw new AlgoliaRuntimeException(
410407
"Content type \"" + contentType + "\" is not supported"
411408
);
412409
}
@@ -418,9 +415,9 @@ public RequestBody serialize(Object obj, String contentType)
418415
* @param <T> Type
419416
* @param call An instance of the Call object
420417
* @return ApiResponse&lt;T&gt;
421-
* @throws ApiException If fail to execute the call
418+
* @throws AlgoliaRuntimeException If fail to execute the call
422419
*/
423-
public <T> ApiResponse<T> execute(Call call) throws ApiException {
420+
public <T> ApiResponse<T> execute(Call call) throws AlgoliaRuntimeException {
424421
return execute(call, null);
425422
}
426423

@@ -432,10 +429,10 @@ public <T> ApiResponse<T> execute(Call call) throws ApiException {
432429
* @param call Call
433430
* @return ApiResponse object containing response status, headers and data, which is a Java object
434431
* deserialized from response body and would be null when returnType is null.
435-
* @throws ApiException If fail to execute the call
432+
* @throws AlgoliaRuntimeException If fail to execute the call
436433
*/
437434
public <T> ApiResponse<T> execute(Call call, Type returnType)
438-
throws ApiException {
435+
throws AlgoliaRuntimeException {
439436
try {
440437
Response response = call.execute();
441438
T data = handleResponse(response, returnType);
@@ -445,7 +442,7 @@ public <T> ApiResponse<T> execute(Call call, Type returnType)
445442
data
446443
);
447444
} catch (IOException e) {
448-
throw new ApiException(e);
445+
throw new AlgoliaRuntimeException(e);
449446
}
450447
}
451448

@@ -478,7 +475,7 @@ public <T> void executeAsync(
478475
new Callback() {
479476
@Override
480477
public void onFailure(Call call, IOException e) {
481-
callback.onFailure(new ApiException(e), 0, null);
478+
callback.onFailure(new AlgoliaRuntimeException(e), 0, null);
482479
}
483480

484481
@Override
@@ -487,7 +484,7 @@ public void onResponse(Call call, Response response)
487484
T result;
488485
try {
489486
result = (T) handleResponse(response, returnType);
490-
} catch (ApiException e) {
487+
} catch (AlgoliaRuntimeException e) {
491488
callback.onFailure(
492489
e,
493490
response.code(),
@@ -496,7 +493,7 @@ public void onResponse(Call call, Response response)
496493
return;
497494
} catch (Exception e) {
498495
callback.onFailure(
499-
new ApiException(e),
496+
new AlgoliaRuntimeException(e),
500497
response.code(),
501498
response.headers().toMultimap()
502499
);
@@ -519,11 +516,11 @@ public void onResponse(Call call, Response response)
519516
* @param response Response
520517
* @param returnType Return type
521518
* @return Type
522-
* @throws ApiException If the response has an unsuccessful status code or fail to deserialize the
523-
* response body
519+
* @throws AlgoliaRuntimeException If the response has an unsuccessful status code or fail to
520+
* deserialize the response body
524521
*/
525522
public <T> T handleResponse(Response response, Type returnType)
526-
throws ApiException {
523+
throws AlgoliaRuntimeException {
527524
if (response.isSuccessful()) {
528525
if (returnType == null || response.code() == 204) {
529526
// returning null if the returnType is not defined,
@@ -532,11 +529,10 @@ public <T> T handleResponse(Response response, Type returnType)
532529
try {
533530
response.body().close();
534531
} catch (Exception e) {
535-
throw new ApiException(
532+
throw new AlgoliaApiException(
536533
response.message(),
537534
e,
538-
response.code(),
539-
response.headers().toMultimap()
535+
response.code()
540536
);
541537
}
542538
}
@@ -545,25 +541,14 @@ public <T> T handleResponse(Response response, Type returnType)
545541
return deserialize(response, returnType);
546542
}
547543
} else {
548-
String respBody = null;
549544
if (response.body() != null) {
550545
try {
551-
respBody = response.body().string();
546+
response.body().string();
552547
} catch (IOException e) {
553-
throw new ApiException(
554-
response.message(),
555-
e,
556-
response.code(),
557-
response.headers().toMultimap()
558-
);
548+
throw new AlgoliaApiException(response.message(), e, response.code());
559549
}
560550
}
561-
throw new ApiException(
562-
response.message(),
563-
response.code(),
564-
response.headers().toMultimap(),
565-
respBody
566-
);
551+
throw new AlgoliaApiException(response.message(), response.code());
567552
}
568553
}
569554

@@ -578,7 +563,7 @@ public <T> T handleResponse(Response response, Type returnType)
578563
* @param headerParams The header parameters
579564
* @param callback Callback for upload/download progress
580565
* @return The HTTP call
581-
* @throws ApiException If fail to serialize the request body object
566+
* @throws AlgoliaRuntimeException If fail to serialize the request body object
582567
*/
583568
public Call buildCall(
584569
String path,
@@ -587,7 +572,7 @@ public Call buildCall(
587572
Object body,
588573
Map<String, String> headerParams,
589574
ApiCallback callback
590-
) throws ApiException {
575+
) throws AlgoliaRuntimeException {
591576
Request request = buildRequest(
592577
path,
593578
method,
@@ -611,7 +596,7 @@ public Call buildCall(
611596
* @param headerParams The header parameters
612597
* @param callback Callback for upload/download progress
613598
* @return The HTTP request
614-
* @throws ApiException If fail to serialize the request body object
599+
* @throws AlgoliaRuntimeException If fail to serialize the request body object
615600
*/
616601
public Request buildRequest(
617602
String path,
@@ -620,7 +605,7 @@ public Request buildRequest(
620605
Object body,
621606
Map<String, String> headerParams,
622607
ApiCallback callback
623-
) throws ApiException {
608+
) throws AlgoliaRuntimeException {
624609
headerParams.put("X-Algolia-Application-Id", this.appId);
625610
headerParams.put("X-Algolia-API-Key", this.apiKey);
626611

@@ -677,7 +662,9 @@ public Request buildRequest(
677662
*/
678663
public String buildUrl(String path, List<Pair> queryParams) {
679664
final StringBuilder url = new StringBuilder();
680-
url.append(basePath).append(path);
665+
666+
// The real host will be assigned by the retry strategy
667+
url.append("http://temp.path").append(path);
681668

682669
if (queryParams != null && !queryParams.isEmpty()) {
683670
// support (constant) query string in `path`, e.g. "/posts?draft=1"

0 commit comments

Comments
 (0)