From e12e57c6e53cf9db3b99c56aa69352eb5c766a22 Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Fri, 19 Dec 2025 20:36:27 +0000 Subject: [PATCH] SDK regeneration --- .fern/metadata.json | 13 ++ README.md | 56 ++++-- build.gradle | 13 +- .../com/pipedream/api/AsyncBaseClient.java | 19 +- .../java/com/pipedream/api/BaseClient.java | 19 +- .../api/core/BaseClientApiException.java | 4 +- .../com/pipedream/api/core/ClientOptions.java | 23 ++- .../api/core/NullableNonemptyFilter.java | 5 +- .../api/core/OAuthTokenSupplier.java | 6 +- .../com/pipedream/api/core/ObjectMappers.java | 9 + .../pipedream/api/core/RetryInterceptor.java | 118 ++++++++++++- .../api/core/pagination/AsyncCustomPager.java | 165 ++++++++++++++++++ .../core/pagination/BiDirectionalPage.java | 60 +++++++ .../api/core/pagination/CustomPager.java | 118 +++++++++++++ .../accounts/AsyncRawAccountsClient.java | 42 ++--- .../resources/accounts/RawAccountsClient.java | 42 ++--- .../actions/AsyncRawActionsClient.java | 59 +++---- .../resources/actions/RawActionsClient.java | 61 +++---- .../AsyncRawAppCategoriesClient.java | 21 +-- .../appcategories/RawAppCategoriesClient.java | 20 +-- .../resources/apps/AsyncRawAppsClient.java | 20 +-- .../api/resources/apps/RawAppsClient.java | 20 +-- .../components/AsyncRawComponentsClient.java | 46 +++-- .../components/RawComponentsClient.java | 48 +++-- .../AsyncRawDeployedTriggersClient.java | 88 ++++------ .../RawDeployedTriggersClient.java | 86 ++++----- .../filestash/AsyncRawFileStashClient.java | 9 +- .../filestash/RawFileStashClient.java | 9 +- .../AsyncRawOauthTokensClient.java | 11 +- .../oauthtokens/RawOauthTokensClient.java | 10 +- .../projects/AsyncRawProjectsClient.java | 65 +++---- .../resources/projects/RawProjectsClient.java | 66 +++---- .../tokens/AsyncRawTokensClient.java | 20 +-- .../api/resources/tokens/RawTokensClient.java | 22 +-- .../triggers/AsyncRawTriggersClient.java | 59 +++---- .../resources/triggers/RawTriggersClient.java | 61 +++---- .../resources/users/AsyncRawUsersClient.java | 6 +- .../api/resources/users/RawUsersClient.java | 6 +- .../java/com/pipedream/api/StreamTest.java | 23 ++- 39 files changed, 974 insertions(+), 574 deletions(-) create mode 100644 .fern/metadata.json create mode 100644 src/main/java/com/pipedream/api/core/pagination/AsyncCustomPager.java create mode 100644 src/main/java/com/pipedream/api/core/pagination/BiDirectionalPage.java create mode 100644 src/main/java/com/pipedream/api/core/pagination/CustomPager.java diff --git a/.fern/metadata.json b/.fern/metadata.json new file mode 100644 index 0000000..e059bc4 --- /dev/null +++ b/.fern/metadata.json @@ -0,0 +1,13 @@ +{ + "cliVersion": "3.29.1", + "generatorName": "fernapi/fern-java-sdk", + "generatorVersion": "3.27.4", + "generatorConfig": { + "publish-to": "central", + "client-class-name": "BaseClient", + "custom-dependencies": [ + "api org.apache.commons:commons-text:1.13.1" + ] + }, + "sdkVersion": "1.1.6" +} \ No newline at end of file diff --git a/README.md b/README.md index ff289f1..7c1303c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ The Pipedream Java library provides convenient access to the Pipedream APIs from - [Retries](#retries) - [Timeouts](#timeouts) - [Custom Headers](#custom-headers) + - [Access Raw Response Data](#access-raw-response-data) - [Contributing](#contributing) - [Reference](#reference) @@ -40,7 +41,7 @@ Add the dependency in your `pom.xml` file: com.pipedream pipedream - 1.1.5 + 1.1.6 ``` @@ -56,12 +57,10 @@ import com.pipedream.api.resources.actions.requests.RunActionOpts; public class Example { public static void main(String[] args) { - BaseClient client = BaseClient - .builder() - .clientId("") - .clientSecret("") + BaseClient client = BaseClient.withCredentials("", "") .projectId("YOUR_PROJECT_ID") - .build(); + .build() + ; client.actions().run( RunActionOpts @@ -73,6 +72,29 @@ public class Example { } } ``` +## Authentication + +This SDK supports two authentication methods: + +### Option 1: Direct Bearer Token + +If you already have a valid access token, you can use it directly: + +```java +BaseClient client = BaseClient.withToken("your-access-token") + .url("https://api.example.com") + .build(); +``` + +### Option 2: OAuth Client Credentials + +The SDK can automatically handle token acquisition and refresh: + +```java +BaseClient client = BaseClient.withCredentials("client-id", "client-secret") + .url("https://api.example.com") + .build(); +``` ## Environments @@ -138,7 +160,9 @@ BaseClient client = BaseClient The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured -retry limit (default: 2). +retry limit (default: 2). Before defaulting to exponential backoff, the SDK will first attempt to respect +the `Retry-After` header (as either in seconds or as an HTTP date), and then the `X-RateLimit-Reset` header +(as a Unix timestamp in epoch seconds); failing both of those, it will fall back to exponential backoff. A request is deemed retryable when any of the following HTTP status codes is returned: @@ -160,7 +184,6 @@ BaseClient client = BaseClient ### Timeouts The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level. - ```java import com.pipedream.api.BaseClient; import com.pipedream.api.core.RequestOptions; @@ -168,7 +191,7 @@ import com.pipedream.api.core.RequestOptions; // Client level BaseClient client = BaseClient .builder() - .timeout(10) + .timeout(60) .build(); // Request level @@ -176,7 +199,7 @@ client.actions().run( ..., RequestOptions .builder() - .timeout(10) + .timeout(60) .build() ); ``` @@ -207,6 +230,19 @@ client.actions().run( ); ``` +### Access Raw Response Data + +The SDK provides access to raw response data, including headers, through the `withRawResponse()` method. +The `withRawResponse()` method returns a raw client that wraps all responses with `body()` and `headers()` methods. +(A normal client's `response` is identical to a raw client's `response.body()`.) + +```java +RunHttpResponse response = client.actions().withRawResponse().run(...); + +System.out.println(response.body()); +System.out.println(response.headers().get("X-My-Header")); +``` + ## Contributing While we value open-source contributions to this SDK, this library is generated programmatically. diff --git a/build.gradle b/build.gradle index 72516ed..1f6345a 100644 --- a/build.gradle +++ b/build.gradle @@ -14,15 +14,14 @@ repositories { } dependencies { - api 'com.squareup.okhttp3:okhttp:4.12.0' - api 'com.fasterxml.jackson.core:jackson-databind:2.17.2' - api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.17.2' - api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2' + api 'com.squareup.okhttp3:okhttp:5.2.1' + api 'com.fasterxml.jackson.core:jackson-databind:2.18.2' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2' + api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' api 'org.apache.commons:commons-text:1.13.1' - testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0' } @@ -49,7 +48,7 @@ java { group = 'com.pipedream' -version = '1.1.5' +version = '1.1.6' jar { dependsOn(":generatePomFileForMavenPublication") @@ -80,7 +79,7 @@ publishing { maven(MavenPublication) { groupId = 'com.pipedream' artifactId = 'pipedream' - version = '1.1.5' + version = '1.1.6' from components.java pom { name = 'pipedream' diff --git a/src/main/java/com/pipedream/api/AsyncBaseClient.java b/src/main/java/com/pipedream/api/AsyncBaseClient.java index 2e3976e..9168d39 100644 --- a/src/main/java/com/pipedream/api/AsyncBaseClient.java +++ b/src/main/java/com/pipedream/api/AsyncBaseClient.java @@ -118,7 +118,22 @@ public AsyncOauthTokensClient oauthTokens() { return this.oauthTokensClient.get(); } - public static AsyncBaseClientBuilder builder() { - return new AsyncBaseClientBuilder(); + /** + * Creates a client builder using a pre-generated access token. + * @param token The access token to use for authentication + * @return A builder configured for token authentication + */ + public static AsyncBaseClientBuilder._TokenAuth withToken(String token) { + return AsyncBaseClientBuilder.withToken(token); + } + + /** + * Creates a client builder using OAuth client credentials. + * @param clientId The OAuth client ID + * @param clientSecret The OAuth client secret + * @return A builder configured for OAuth authentication + */ + public static AsyncBaseClientBuilder._CredentialsAuth withCredentials(String clientId, String clientSecret) { + return AsyncBaseClientBuilder.withCredentials(clientId, clientSecret); } } diff --git a/src/main/java/com/pipedream/api/BaseClient.java b/src/main/java/com/pipedream/api/BaseClient.java index 387fe22..f645eee 100644 --- a/src/main/java/com/pipedream/api/BaseClient.java +++ b/src/main/java/com/pipedream/api/BaseClient.java @@ -118,7 +118,22 @@ public OauthTokensClient oauthTokens() { return this.oauthTokensClient.get(); } - public static BaseClientBuilder builder() { - return new BaseClientBuilder(); + /** + * Creates a client builder using a pre-generated access token. + * @param token The access token to use for authentication + * @return A builder configured for token authentication + */ + public static BaseClientBuilder._TokenAuth withToken(String token) { + return BaseClientBuilder.withToken(token); + } + + /** + * Creates a client builder using OAuth client credentials. + * @param clientId The OAuth client ID + * @param clientSecret The OAuth client secret + * @return A builder configured for OAuth authentication + */ + public static BaseClientBuilder._CredentialsAuth withCredentials(String clientId, String clientSecret) { + return BaseClientBuilder.withCredentials(clientId, clientSecret); } } diff --git a/src/main/java/com/pipedream/api/core/BaseClientApiException.java b/src/main/java/com/pipedream/api/core/BaseClientApiException.java index a2680b0..f0e59f6 100644 --- a/src/main/java/com/pipedream/api/core/BaseClientApiException.java +++ b/src/main/java/com/pipedream/api/core/BaseClientApiException.java @@ -65,9 +65,9 @@ public Map> headers() { return this.headers; } - @java.lang.Override + @Override public String toString() { return "BaseClientApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: " - + body + "}"; + + ObjectMappers.stringify(body) + "}"; } } diff --git a/src/main/java/com/pipedream/api/core/ClientOptions.java b/src/main/java/com/pipedream/api/core/ClientOptions.java index 5964fab..b038c92 100644 --- a/src/main/java/com/pipedream/api/core/ClientOptions.java +++ b/src/main/java/com/pipedream/api/core/ClientOptions.java @@ -21,6 +21,8 @@ public final class ClientOptions { private final int timeout; + private final int maxRetries; + private String projectId; private ClientOptions( @@ -29,21 +31,23 @@ private ClientOptions( Map> headerSuppliers, OkHttpClient httpClient, int timeout, + int maxRetries, String projectId) { this.environment = environment; this.headers = new HashMap<>(); this.headers.putAll(headers); this.headers.putAll(new HashMap() { { - put("User-Agent", "com.pipedream:pipedream/1.1.5"); + put("User-Agent", "com.pipedream:pipedream/1.1.6"); put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.pipedream.fern:api-sdk"); - put("X-Fern-SDK-Version", "1.1.5"); + put("X-Fern-SDK-Version", "1.1.6"); } }); this.headerSuppliers = headerSuppliers; this.httpClient = httpClient; this.timeout = timeout; + this.maxRetries = maxRetries; this.projectId = projectId; } @@ -86,6 +90,10 @@ public OkHttpClient httpClientWithTimeout(RequestOptions requestOptions) { .build(); } + public int maxRetries() { + return this.maxRetries; + } + public String projectId() { return this.projectId; } @@ -181,7 +189,13 @@ public ClientOptions build() { this.timeout = Optional.of(httpClient.callTimeoutMillis() / 1000); return new ClientOptions( - environment, headers, headerSuppliers, httpClient, this.timeout.get(), this.projectId); + environment, + headers, + headerSuppliers, + httpClient, + this.timeout.get(), + this.maxRetries, + this.projectId); } /** @@ -192,6 +206,9 @@ public static Builder from(ClientOptions clientOptions) { builder.environment = clientOptions.environment(); builder.timeout = Optional.of(clientOptions.timeout(null)); builder.httpClient = clientOptions.httpClient(); + builder.headers.putAll(clientOptions.headers); + builder.headerSuppliers.putAll(clientOptions.headerSuppliers); + builder.maxRetries = clientOptions.maxRetries(); builder.projectId = clientOptions.projectId(); return builder; } diff --git a/src/main/java/com/pipedream/api/core/NullableNonemptyFilter.java b/src/main/java/com/pipedream/api/core/NullableNonemptyFilter.java index afad6eb..c268e6e 100644 --- a/src/main/java/com/pipedream/api/core/NullableNonemptyFilter.java +++ b/src/main/java/com/pipedream/api/core/NullableNonemptyFilter.java @@ -14,6 +14,9 @@ public boolean equals(Object o) { } private boolean isOptionalEmpty(Object o) { - return o instanceof Optional && !((Optional) o).isPresent(); + if (o instanceof Optional) { + return !((Optional) o).isPresent(); + } + return false; } } diff --git a/src/main/java/com/pipedream/api/core/OAuthTokenSupplier.java b/src/main/java/com/pipedream/api/core/OAuthTokenSupplier.java index ddbde79..66c8adf 100644 --- a/src/main/java/com/pipedream/api/core/OAuthTokenSupplier.java +++ b/src/main/java/com/pipedream/api/core/OAuthTokenSupplier.java @@ -17,15 +17,18 @@ public final class OAuthTokenSupplier implements Supplier { private final String clientSecret; + private final String scope; + private final OauthTokensClient authClient; private String accessToken; private Instant expiresAt; - public OAuthTokenSupplier(String clientId, String clientSecret, OauthTokensClient authClient) { + public OAuthTokenSupplier(String clientId, String clientSecret, String scope, OauthTokensClient authClient) { this.clientId = clientId; this.clientSecret = clientSecret; + this.scope = scope; this.authClient = authClient; this.expiresAt = Instant.now(); } @@ -34,6 +37,7 @@ public CreateOAuthTokenResponse fetchToken() { CreateOAuthTokenOpts getTokenRequest = CreateOAuthTokenOpts.builder() .clientId(clientId) .clientSecret(clientSecret) + .scope(scope) .build(); return authClient.create(getTokenRequest); } diff --git a/src/main/java/com/pipedream/api/core/ObjectMappers.java b/src/main/java/com/pipedream/api/core/ObjectMappers.java index 6dd6c3c..aa3ba10 100644 --- a/src/main/java/com/pipedream/api/core/ObjectMappers.java +++ b/src/main/java/com/pipedream/api/core/ObjectMappers.java @@ -4,6 +4,7 @@ package com.pipedream.api.core; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -33,4 +34,12 @@ public static String stringify(Object o) { return o.getClass().getName() + "@" + Integer.toHexString(o.hashCode()); } } + + public static Object parseErrorBody(String responseBodyString) { + try { + return JSON_MAPPER.readValue(responseBodyString, Object.class); + } catch (JsonProcessingException ignored) { + return responseBodyString; + } + } } diff --git a/src/main/java/com/pipedream/api/core/RetryInterceptor.java b/src/main/java/com/pipedream/api/core/RetryInterceptor.java index 66b6be4..da07beb 100644 --- a/src/main/java/com/pipedream/api/core/RetryInterceptor.java +++ b/src/main/java/com/pipedream/api/core/RetryInterceptor.java @@ -5,6 +5,9 @@ import java.io.IOException; import java.time.Duration; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.Optional; import java.util.Random; import okhttp3.Interceptor; @@ -12,7 +15,10 @@ public class RetryInterceptor implements Interceptor { - private static final Duration ONE_SECOND = Duration.ofSeconds(1); + private static final Duration INITIAL_RETRY_DELAY = Duration.ofMillis(1000); + private static final Duration MAX_RETRY_DELAY = Duration.ofMillis(60000); + private static final double JITTER_FACTOR = 0.2; + private final ExponentialBackoff backoff; private final Random random = new Random(); @@ -32,7 +38,7 @@ public Response intercept(Chain chain) throws IOException { } private Response retryChain(Response response, Chain chain) throws IOException { - Optional nextBackoff = this.backoff.nextBackoff(); + Optional nextBackoff = this.backoff.nextBackoff(response); while (nextBackoff.isPresent()) { try { Thread.sleep(nextBackoff.get().toMillis()); @@ -42,7 +48,7 @@ private Response retryChain(Response response, Chain chain) throws IOException { response.close(); response = chain.proceed(chain.request()); if (shouldRetry(response.code())) { - nextBackoff = this.backoff.nextBackoff(); + nextBackoff = this.backoff.nextBackoff(response); } else { return response; } @@ -51,6 +57,102 @@ private Response retryChain(Response response, Chain chain) throws IOException { return response; } + /** + * Calculates the retry delay from response headers, with fallback to exponential backoff. + * Priority: Retry-After > X-RateLimit-Reset > Exponential Backoff + */ + private Duration getRetryDelayFromHeaders(Response response, int retryAttempt) { + // Check for Retry-After header first (RFC 7231), with no jitter + String retryAfter = response.header("Retry-After"); + if (retryAfter != null) { + // Parse as number of seconds... + Optional secondsDelay = tryParseLong(retryAfter) + .map(seconds -> seconds * 1000) + .filter(delayMs -> delayMs > 0) + .map(delayMs -> Math.min(delayMs, MAX_RETRY_DELAY.toMillis())) + .map(Duration::ofMillis); + if (secondsDelay.isPresent()) { + return secondsDelay.get(); + } + + // ...or as an HTTP date; both are valid + Optional dateDelay = tryParseHttpDate(retryAfter) + .map(resetTime -> resetTime.toInstant().toEpochMilli() - System.currentTimeMillis()) + .filter(delayMs -> delayMs > 0) + .map(delayMs -> Math.min(delayMs, MAX_RETRY_DELAY.toMillis())) + .map(Duration::ofMillis); + if (dateDelay.isPresent()) { + return dateDelay.get(); + } + } + + // Then check for industry-standard X-RateLimit-Reset header, with positive jitter + String rateLimitReset = response.header("X-RateLimit-Reset"); + if (rateLimitReset != null) { + // Assume Unix timestamp in epoch seconds + Optional rateLimitDelay = tryParseLong(rateLimitReset) + .map(resetTimeSeconds -> (resetTimeSeconds * 1000) - System.currentTimeMillis()) + .filter(delayMs -> delayMs > 0) + .map(delayMs -> Math.min(delayMs, MAX_RETRY_DELAY.toMillis())) + .map(this::addPositiveJitter) + .map(Duration::ofMillis); + if (rateLimitDelay.isPresent()) { + return rateLimitDelay.get(); + } + } + + // Fall back to exponential backoff, with symmetric jitter + long baseDelay = INITIAL_RETRY_DELAY.toMillis() * (1L << retryAttempt); // 2^retryAttempt + long cappedDelay = Math.min(baseDelay, MAX_RETRY_DELAY.toMillis()); + return Duration.ofMillis(addSymmetricJitter(cappedDelay)); + } + + /** + * Attempts to parse a string as a long, returning empty Optional on failure. + */ + private Optional tryParseLong(String value) { + if (value == null) { + return Optional.empty(); + } + try { + return Optional.of(Long.parseLong(value)); + } catch (NumberFormatException e) { + return Optional.empty(); + } + } + + /** + * Attempts to parse a string as an HTTP date (RFC 1123), returning empty Optional on failure. + */ + private Optional tryParseHttpDate(String value) { + if (value == null) { + return Optional.empty(); + } + try { + return Optional.of(ZonedDateTime.parse(value, DateTimeFormatter.RFC_1123_DATE_TIME)); + } catch (DateTimeParseException e) { + return Optional.empty(); + } + } + + /** + * Adds positive jitter (100-120% of original value) to prevent thundering herd. + * Used for X-RateLimit-Reset header delays. + */ + private long addPositiveJitter(long delayMs) { + double jitterMultiplier = 1.0 + (random.nextDouble() * JITTER_FACTOR); + return (long) (delayMs * jitterMultiplier); + } + + /** + * Adds symmetric jitter (90-110% of original value) to prevent thundering herd. + * Used for exponential backoff delays. + */ + private long addSymmetricJitter(long delayMs) { + double jitterMultiplier = 1.0 + ((random.nextDouble() - 0.5) * JITTER_FACTOR); + return (long) (delayMs * jitterMultiplier); + } + private static boolean shouldRetry(int statusCode) { return statusCode == 408 || statusCode == 429 || statusCode >= 500; } @@ -65,14 +167,14 @@ private final class ExponentialBackoff { this.maxNumRetries = maxNumRetries; } - public Optional nextBackoff() { - retryNumber += 1; - if (retryNumber > maxNumRetries) { + public Optional nextBackoff(Response response) { + if (retryNumber >= maxNumRetries) { return Optional.empty(); } - int upperBound = (int) Math.pow(2, retryNumber); - return Optional.of(ONE_SECOND.multipliedBy(random.nextInt(upperBound))); + Duration delay = getRetryDelayFromHeaders(response, retryNumber); + retryNumber += 1; + return Optional.of(delay); } } } diff --git a/src/main/java/com/pipedream/api/core/pagination/AsyncCustomPager.java b/src/main/java/com/pipedream/api/core/pagination/AsyncCustomPager.java new file mode 100644 index 0000000..40ba44c --- /dev/null +++ b/src/main/java/com/pipedream/api/core/pagination/AsyncCustomPager.java @@ -0,0 +1,165 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.pipedream.api.core.pagination; + +import com.pipedream.api.core.ClientOptions; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +/** + * Skeleton implementation for custom asynchronous bidirectional pagination. + * + * THIS CLASS MUST BE IMPLEMENTED BY THE USER. + * + * This file is added to .fernignore and will not be regenerated. + * Replace this skeleton implementation with your custom async pagination logic + * that handles your API's specific pagination structure (e.g., HATEOAS links). + * + * Example implementation for HATEOAS-style async pagination: + *
{@code
+ * public class AsyncCustomPager implements BiDirectionalPage {
+ *     private final List items;
+ *     private final String nextUrl;
+ *     private final String previousUrl;
+ *     private final AsyncHttpClient client;
+ *
+ *     public AsyncCustomPager(Response response, AsyncHttpClient client, ...) {
+ *         this.items = response.getData();
+ *         this.nextUrl = response.getLinks().getNext();
+ *         this.previousUrl = response.getLinks().getPrevious();
+ *         // ... store other needed context
+ *     }
+ *
+ *     @Override
+ *     public boolean hasNext() {
+ *         return nextUrl != null;
+ *     }
+ *
+ *     @Override
+ *     public CompletableFuture> nextPageAsync() {
+ *         if (!hasNext()) {
+ *             CompletableFuture> future = new CompletableFuture<>();
+ *             future.completeExceptionally(new NoSuchElementException("No next page available"));
+ *             return future;
+ *         }
+ *         // Make async HTTP request to nextUrl
+ *         return client.getAsync(nextUrl)
+ *             .thenApply(response -> new AsyncCustomPager<>(response, client, ...));
+ *     }
+ *
+ *     // ... implement other methods
+ * }
+ * }
+ * + * @param The type of items in the page + */ +public class AsyncCustomPager implements BiDirectionalPage { + + /** + * Create an AsyncCustomPager from an initial response. + * + * @param initialResponse The first page response from the API + * @param clientOptions The client options containing HTTP client and other configuration + * @param requestOptions Request options for authentication, headers, etc. + * @return A CompletableFuture containing the new AsyncCustomPager instance + */ + public static CompletableFuture> createAsync( + Object initialResponse, ClientOptions clientOptions, Object requestOptions) { + throw new UnsupportedOperationException("AsyncCustomPager must be implemented. " + + "Please implement this class in core/AsyncCustomPager.java to define your async pagination logic. " + + "This file has been added to .fernignore and will not be overwritten. " + + "See the class documentation for implementation examples."); + } + + @Override + public boolean hasNext() { + throw new UnsupportedOperationException("AsyncCustomPager.hasNext() must be implemented. " + + "This method should return true if a next page is available."); + } + + @Override + public boolean hasPrevious() { + throw new UnsupportedOperationException("AsyncCustomPager.hasPrevious() must be implemented. " + + "This method should return true if a previous page is available."); + } + + /** + * Asynchronously fetch the next page. + * + * @return A CompletableFuture that completes with the next page + * @throws java.util.NoSuchElementException if no next page exists (wrapped in CompletableFuture) + */ + public CompletableFuture> nextPageAsync() { + CompletableFuture> future = new CompletableFuture<>(); + future.completeExceptionally( + new UnsupportedOperationException("AsyncCustomPager.nextPageAsync() must be implemented. " + + "This method should asynchronously fetch and return the next page of results.")); + return future; + } + + /** + * Asynchronously fetch the previous page. + * + * @return A CompletableFuture that completes with the previous page + * @throws java.util.NoSuchElementException if no previous page exists (wrapped in CompletableFuture) + */ + public CompletableFuture> previousPageAsync() { + CompletableFuture> future = new CompletableFuture<>(); + future.completeExceptionally( + new UnsupportedOperationException("AsyncCustomPager.previousPageAsync() must be implemented. " + + "This method should asynchronously fetch and return the previous page of results.")); + return future; + } + + @Override + public BiDirectionalPage nextPage() throws IOException { + throw new UnsupportedOperationException("AsyncCustomPager.nextPage() must be implemented. " + + "Consider using nextPageAsync() for async operations, or implement synchronous blocking version."); + } + + @Override + public BiDirectionalPage previousPage() throws IOException { + throw new UnsupportedOperationException( + "AsyncCustomPager.previousPage() must be implemented. " + + "Consider using previousPageAsync() for async operations, or implement synchronous blocking version."); + } + + @Override + public List getItems() { + throw new UnsupportedOperationException("AsyncCustomPager.getItems() must be implemented. " + + "This method should return the items in the current page."); + } + + @Override + public Optional getResponse() { + throw new UnsupportedOperationException("AsyncCustomPager.getResponse() must be implemented. " + + "This method should return the full response object for accessing pagination metadata."); + } + + /** + * Asynchronously iterate through all pages starting from current. + * Returns a CompletableFuture that completes with all items from all pages. + * + * @return CompletableFuture containing all items across all pages + */ + public CompletableFuture> getAllItemsAsync() { + throw new UnsupportedOperationException("AsyncCustomPager.getAllItemsAsync() must be implemented. " + + "This method should asynchronously fetch all pages and return all items."); + } + + /** + * Process each page asynchronously as it arrives. + * + * @param pageProcessor Function to process each page + * @return CompletableFuture that completes when all pages are processed + */ + public CompletableFuture forEachPageAsync( + java.util.function.Function, CompletionStage> pageProcessor) { + throw new UnsupportedOperationException("AsyncCustomPager.forEachPageAsync() must be implemented. " + + "This method should asynchronously process each page with the given function."); + } +} diff --git a/src/main/java/com/pipedream/api/core/pagination/BiDirectionalPage.java b/src/main/java/com/pipedream/api/core/pagination/BiDirectionalPage.java new file mode 100644 index 0000000..2d21d7c --- /dev/null +++ b/src/main/java/com/pipedream/api/core/pagination/BiDirectionalPage.java @@ -0,0 +1,60 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.pipedream.api.core.pagination; + +import java.util.List; + +/** + * Interface for pages that support bidirectional pagination (both forward and backward navigation). + * This is used for custom pagination scenarios where the API provides both next and previous page links. + * + * @param The type of items in the page + */ +public interface BiDirectionalPage { + /** + * Returns whether there is a next page available. + * + * @return true if next page exists and can be fetched + */ + boolean hasNext(); + + /** + * Returns whether there is a previous page available. + * + * @return true if previous page exists and can be fetched + */ + boolean hasPrevious(); + + /** + * Fetches and returns the next page. + * + * @return the next page + * @throws java.util.NoSuchElementException if no next page exists + * @throws java.io.IOException if the HTTP request fails + */ + BiDirectionalPage nextPage() throws java.io.IOException; + + /** + * Fetches and returns the previous page. + * + * @return the previous page + * @throws java.util.NoSuchElementException if no previous page exists + * @throws java.io.IOException if the HTTP request fails + */ + BiDirectionalPage previousPage() throws java.io.IOException; + + /** + * Returns the items in the current page. + * + * @return list of items in this page + */ + List getItems(); + + /** + * Returns the full response object for accessing pagination metadata. + * + * @return Optional containing the response, or empty if unavailable + */ + java.util.Optional getResponse(); +} diff --git a/src/main/java/com/pipedream/api/core/pagination/CustomPager.java b/src/main/java/com/pipedream/api/core/pagination/CustomPager.java new file mode 100644 index 0000000..4397478 --- /dev/null +++ b/src/main/java/com/pipedream/api/core/pagination/CustomPager.java @@ -0,0 +1,118 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.pipedream.api.core.pagination; + +import com.pipedream.api.core.ClientOptions; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; + +/** + * Skeleton implementation for custom bidirectional pagination. + * + * THIS CLASS MUST BE IMPLEMENTED BY THE USER. + * + * This file is added to .fernignore and will not be regenerated. + * Replace this skeleton implementation with your custom pagination logic + * that handles your API's specific pagination structure (e.g., HATEOAS links). + * + * Example implementation for HATEOAS-style pagination: + *
{@code
+ * public class CustomPager implements BiDirectionalPage, Iterable {
+ *     private final List items;
+ *     private final String nextUrl;
+ *     private final String previousUrl;
+ *     private final OkHttpClient client;
+ *     private final TypeReference> responseType;
+ *
+ *     public CustomPager(Response response, OkHttpClient client, ...) {
+ *         this.items = response.getData();
+ *         this.nextUrl = response.getLinks().getNext();
+ *         this.previousUrl = response.getLinks().getPrevious();
+ *         // ... store other needed context
+ *     }
+ *
+ *     @Override
+ *     public boolean hasNext() {
+ *         return nextUrl != null;
+ *     }
+ *
+ *     @Override
+ *     public CustomPager nextPage() throws IOException {
+ *         if (!hasNext()) {
+ *             throw new NoSuchElementException("No next page available");
+ *         }
+ *         // Make HTTP request to nextUrl
+ *         // Parse response
+ *         // Return new CustomPager instance
+ *     }
+ *
+ *     // ... implement other methods
+ * }
+ * }
+ * + * @param The type of items in the page + */ +public class CustomPager implements BiDirectionalPage, Iterable { + + /** + * Create a CustomPager from an initial response. + * + * @param initialResponse The first page response from the API + * @param clientOptions The client options containing HTTP client and other configuration + * @param requestOptions Request options for authentication, headers, etc. + * @return A new CustomPager instance + * @throws IOException if the request fails + */ + public static CustomPager create(Object initialResponse, ClientOptions clientOptions, Object requestOptions) + throws IOException { + throw new UnsupportedOperationException("CustomPager must be implemented. " + + "Please implement this class in core/CustomPager.java to define your pagination logic. " + + "This file has been added to .fernignore and will not be overwritten. " + + "See the class documentation for implementation examples."); + } + + @Override + public boolean hasNext() { + throw new UnsupportedOperationException("CustomPager.hasNext() must be implemented. " + + "This method should return true if a next page is available."); + } + + @Override + public boolean hasPrevious() { + throw new UnsupportedOperationException("CustomPager.hasPrevious() must be implemented. " + + "This method should return true if a previous page is available."); + } + + @Override + public BiDirectionalPage nextPage() throws IOException { + throw new UnsupportedOperationException("CustomPager.nextPage() must be implemented. " + + "This method should fetch and return the next page of results."); + } + + @Override + public BiDirectionalPage previousPage() throws IOException { + throw new UnsupportedOperationException("CustomPager.previousPage() must be implemented. " + + "This method should fetch and return the previous page of results."); + } + + @Override + public List getItems() { + throw new UnsupportedOperationException("CustomPager.getItems() must be implemented. " + + "This method should return the items in the current page."); + } + + @Override + public Optional getResponse() { + throw new UnsupportedOperationException("CustomPager.getResponse() must be implemented. " + + "This method should return the full response object for accessing pagination metadata."); + } + + @Override + public Iterator iterator() { + throw new UnsupportedOperationException("CustomPager.iterator() must be implemented. " + + "This method should return an iterator that traverses all items across all pages."); + } +} diff --git a/src/main/java/com/pipedream/api/resources/accounts/AsyncRawAccountsClient.java b/src/main/java/com/pipedream/api/resources/accounts/AsyncRawAccountsClient.java index dd95b5f..2e1566a 100644 --- a/src/main/java/com/pipedream/api/resources/accounts/AsyncRawAccountsClient.java +++ b/src/main/java/com/pipedream/api/resources/accounts/AsyncRawAccountsClient.java @@ -111,9 +111,10 @@ public CompletableFuture>> li @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListAccountsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListAccountsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListAccountsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); AccountsListRequest nextRequest = AccountsListRequest.builder() @@ -135,7 +136,6 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -145,11 +145,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -212,12 +210,12 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Account.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Account.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -227,11 +225,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -294,12 +290,12 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Account.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Account.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -309,11 +305,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -375,11 +369,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -442,11 +434,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/accounts/RawAccountsClient.java b/src/main/java/com/pipedream/api/resources/accounts/RawAccountsClient.java index 777be36..c46f19e 100644 --- a/src/main/java/com/pipedream/api/resources/accounts/RawAccountsClient.java +++ b/src/main/java/com/pipedream/api/resources/accounts/RawAccountsClient.java @@ -103,9 +103,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListAccountsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListAccountsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListAccountsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); AccountsListRequest nextRequest = AccountsListRequest.builder() .from(request) @@ -118,7 +119,6 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -127,11 +127,9 @@ public BaseClientHttpResponse> list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -181,11 +179,11 @@ public BaseClientHttpResponse create(CreateAccountOpts request, Request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Account.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Account.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -194,11 +192,9 @@ public BaseClientHttpResponse create(CreateAccountOpts request, Request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -248,11 +244,11 @@ public BaseClientHttpResponse retrieve( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Account.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Account.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -261,11 +257,9 @@ public BaseClientHttpResponse retrieve( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -313,11 +307,9 @@ public BaseClientHttpResponse delete(String accountId, RequestOptions requ } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -366,11 +358,9 @@ public BaseClientHttpResponse deleteByApp(String appId, RequestOptions req } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/actions/AsyncRawActionsClient.java b/src/main/java/com/pipedream/api/resources/actions/AsyncRawActionsClient.java index db2d6db..bd8df19 100644 --- a/src/main/java/com/pipedream/api/resources/actions/AsyncRawActionsClient.java +++ b/src/main/java/com/pipedream/api/resources/actions/AsyncRawActionsClient.java @@ -110,9 +110,10 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); ActionsListRequest nextRequest = ActionsListRequest.builder() @@ -134,7 +135,6 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 400: @@ -151,11 +151,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -215,13 +213,13 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -231,11 +229,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -266,7 +262,8 @@ public CompletableFuture> configur .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("actions/configure") + .addPathSegments("actions") + .addPathSegments("configure") .build(); RequestBody body; try { @@ -291,13 +288,13 @@ public CompletableFuture> configur @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ConfigurePropResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ConfigurePropResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -307,11 +304,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -342,7 +337,8 @@ public CompletableFuture> reloadProp .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("actions/props") + .addPathSegments("actions") + .addPathSegments("props") .build(); RequestBody body; try { @@ -367,13 +363,13 @@ public CompletableFuture> reloadProp @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ReloadPropsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReloadPropsResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -383,11 +379,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -418,7 +412,8 @@ public CompletableFuture> run( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("actions/run") + .addPathSegments("actions") + .addPathSegments("run") .build(); RequestBody body; try { @@ -443,13 +438,13 @@ public CompletableFuture> run( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RunActionResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RunActionResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -459,11 +454,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/actions/RawActionsClient.java b/src/main/java/com/pipedream/api/resources/actions/RawActionsClient.java index 902614e..438895a 100644 --- a/src/main/java/com/pipedream/api/resources/actions/RawActionsClient.java +++ b/src/main/java/com/pipedream/api/resources/actions/RawActionsClient.java @@ -102,9 +102,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); ActionsListRequest nextRequest = ActionsListRequest.builder() .from(request) @@ -117,7 +118,6 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 400: @@ -130,11 +130,9 @@ public BaseClientHttpResponse> list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -181,12 +179,12 @@ public BaseClientHttpResponse retrieve( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -195,11 +193,9 @@ public BaseClientHttpResponse retrieve( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -221,7 +217,8 @@ public BaseClientHttpResponse configureProp( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("actions/configure") + .addPathSegments("actions") + .addPathSegments("configure") .build(); RequestBody body; try { @@ -243,12 +240,11 @@ public BaseClientHttpResponse configureProp( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ConfigurePropResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ConfigurePropResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -257,11 +253,9 @@ public BaseClientHttpResponse configureProp( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -283,7 +277,8 @@ public BaseClientHttpResponse reloadProps( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("actions/props") + .addPathSegments("actions") + .addPathSegments("props") .build(); RequestBody body; try { @@ -305,12 +300,11 @@ public BaseClientHttpResponse reloadProps( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ReloadPropsResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReloadPropsResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -319,11 +313,9 @@ public BaseClientHttpResponse reloadProps( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -344,7 +336,8 @@ public BaseClientHttpResponse run(RunActionOpts request, Requ .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("actions/run") + .addPathSegments("actions") + .addPathSegments("run") .build(); RequestBody body; try { @@ -366,11 +359,11 @@ public BaseClientHttpResponse run(RunActionOpts request, Requ } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RunActionResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, RunActionResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -379,11 +372,9 @@ public BaseClientHttpResponse run(RunActionOpts request, Requ } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/appcategories/AsyncRawAppCategoriesClient.java b/src/main/java/com/pipedream/api/resources/appcategories/AsyncRawAppCategoriesClient.java index ea828f1..a8e5d04 100644 --- a/src/main/java/com/pipedream/api/resources/appcategories/AsyncRawAppCategoriesClient.java +++ b/src/main/java/com/pipedream/api/resources/appcategories/AsyncRawAppCategoriesClient.java @@ -61,19 +61,17 @@ public CompletableFuture>> list(Request @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), new TypeReference>() {}), + responseBodyString, new TypeReference>() {}), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -119,18 +117,15 @@ public CompletableFuture> retrieve(String id @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AppCategory.class), - response)); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AppCategory.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/appcategories/RawAppCategoriesClient.java b/src/main/java/com/pipedream/api/resources/appcategories/RawAppCategoriesClient.java index 401fd49..4a40980 100644 --- a/src/main/java/com/pipedream/api/resources/appcategories/RawAppCategoriesClient.java +++ b/src/main/java/com/pipedream/api/resources/appcategories/RawAppCategoriesClient.java @@ -54,18 +54,16 @@ public BaseClientHttpResponse> list(RequestOptions requestOpti } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), new TypeReference>() {}), + responseBodyString, new TypeReference>() {}), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -99,16 +97,14 @@ public BaseClientHttpResponse retrieve(String id, RequestOptions re } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), AppCategory.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, AppCategory.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/apps/AsyncRawAppsClient.java b/src/main/java/com/pipedream/api/resources/apps/AsyncRawAppsClient.java index 63900eb..7471fca 100644 --- a/src/main/java/com/pipedream/api/resources/apps/AsyncRawAppsClient.java +++ b/src/main/java/com/pipedream/api/resources/apps/AsyncRawAppsClient.java @@ -113,9 +113,10 @@ public CompletableFuture>> list( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListAppsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListAppsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListAppsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); AppsListRequest nextRequest = AppsListRequest.builder() @@ -136,12 +137,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -188,18 +186,16 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetAppResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetAppResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/apps/RawAppsClient.java b/src/main/java/com/pipedream/api/resources/apps/RawAppsClient.java index 403f724..e927b9d 100644 --- a/src/main/java/com/pipedream/api/resources/apps/RawAppsClient.java +++ b/src/main/java/com/pipedream/api/resources/apps/RawAppsClient.java @@ -105,9 +105,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListAppsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListAppsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListAppsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); AppsListRequest nextRequest = AppsListRequest.builder() .from(request) @@ -120,12 +121,9 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -159,16 +157,14 @@ public BaseClientHttpResponse retrieve(String appId, RequestOpti } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetAppResponse.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetAppResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/components/AsyncRawComponentsClient.java b/src/main/java/com/pipedream/api/resources/components/AsyncRawComponentsClient.java index 7ad7e19..8dc133d 100644 --- a/src/main/java/com/pipedream/api/resources/components/AsyncRawComponentsClient.java +++ b/src/main/java/com/pipedream/api/resources/components/AsyncRawComponentsClient.java @@ -113,9 +113,10 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); ComponentsListRequest nextRequest = ComponentsListRequest.builder() @@ -137,7 +138,6 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 400: @@ -154,11 +154,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -218,13 +216,13 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -234,11 +232,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -269,7 +265,8 @@ public CompletableFuture> configur .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("components/configure") + .addPathSegments("components") + .addPathSegments("configure") .build(); RequestBody body; try { @@ -294,13 +291,13 @@ public CompletableFuture> configur @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ConfigurePropResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ConfigurePropResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -310,11 +307,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -345,7 +340,8 @@ public CompletableFuture> reloadProp .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("components/props") + .addPathSegments("components") + .addPathSegments("props") .build(); RequestBody body; try { @@ -370,13 +366,13 @@ public CompletableFuture> reloadProp @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ReloadPropsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReloadPropsResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -386,11 +382,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/components/RawComponentsClient.java b/src/main/java/com/pipedream/api/resources/components/RawComponentsClient.java index b5a237f..e186a63 100644 --- a/src/main/java/com/pipedream/api/resources/components/RawComponentsClient.java +++ b/src/main/java/com/pipedream/api/resources/components/RawComponentsClient.java @@ -104,9 +104,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); ComponentsListRequest nextRequest = ComponentsListRequest.builder() .from(request) @@ -119,7 +120,6 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 400: @@ -132,11 +132,9 @@ public BaseClientHttpResponse> list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -183,12 +181,12 @@ public BaseClientHttpResponse retrieve( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -197,11 +195,9 @@ public BaseClientHttpResponse retrieve( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -223,7 +219,8 @@ public BaseClientHttpResponse configureProp( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("components/configure") + .addPathSegments("components") + .addPathSegments("configure") .build(); RequestBody body; try { @@ -245,12 +242,11 @@ public BaseClientHttpResponse configureProp( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ConfigurePropResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ConfigurePropResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -259,11 +255,9 @@ public BaseClientHttpResponse configureProp( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -285,7 +279,8 @@ public BaseClientHttpResponse reloadProps( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("components/props") + .addPathSegments("components") + .addPathSegments("props") .build(); RequestBody body; try { @@ -307,12 +302,11 @@ public BaseClientHttpResponse reloadProps( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ReloadPropsResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReloadPropsResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -321,11 +315,9 @@ public BaseClientHttpResponse reloadProps( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/deployedtriggers/AsyncRawDeployedTriggersClient.java b/src/main/java/com/pipedream/api/resources/deployedtriggers/AsyncRawDeployedTriggersClient.java index 0542a9c..9f23ad1 100644 --- a/src/main/java/com/pipedream/api/resources/deployedtriggers/AsyncRawDeployedTriggersClient.java +++ b/src/main/java/com/pipedream/api/resources/deployedtriggers/AsyncRawDeployedTriggersClient.java @@ -103,9 +103,10 @@ public CompletableFuture>> li @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggersResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggersResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggersResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); DeployedTriggersListRequest nextRequest = DeployedTriggersListRequest.builder() @@ -127,7 +128,6 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -137,11 +137,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -191,13 +189,13 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggerResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -207,11 +205,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -268,13 +264,13 @@ public CompletableFuture> update( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggerResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -284,11 +280,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -356,11 +350,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -414,13 +406,13 @@ public CompletableFuture>> listEvents( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { - GetTriggerEventsResponse parsedResponse = ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), GetTriggerEventsResponse.class); + GetTriggerEventsResponse parsedResponse = + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerEventsResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -430,11 +422,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -485,14 +475,14 @@ public CompletableFuture> li @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), GetTriggerWorkflowsResponse.class), + responseBodyString, GetTriggerWorkflowsResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -502,11 +492,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -565,14 +553,14 @@ public CompletableFuture> up @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), GetTriggerWorkflowsResponse.class), + responseBodyString, GetTriggerWorkflowsResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -582,11 +570,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -637,14 +623,14 @@ public CompletableFuture> lis @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), GetTriggerWebhooksResponse.class), + responseBodyString, GetTriggerWebhooksResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -654,11 +640,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -717,14 +701,14 @@ public CompletableFuture> upd @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), GetTriggerWebhooksResponse.class), + responseBodyString, GetTriggerWebhooksResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -734,11 +718,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/deployedtriggers/RawDeployedTriggersClient.java b/src/main/java/com/pipedream/api/resources/deployedtriggers/RawDeployedTriggersClient.java index f5f5117..83bd803 100644 --- a/src/main/java/com/pipedream/api/resources/deployedtriggers/RawDeployedTriggersClient.java +++ b/src/main/java/com/pipedream/api/resources/deployedtriggers/RawDeployedTriggersClient.java @@ -94,9 +94,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggersResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggersResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggersResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); DeployedTriggersListRequest nextRequest = DeployedTriggersListRequest.builder() .from(request) @@ -109,7 +110,6 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -118,11 +118,9 @@ public BaseClientHttpResponse> list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -159,12 +157,12 @@ public BaseClientHttpResponse retrieve( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggerResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -173,11 +171,9 @@ public BaseClientHttpResponse retrieve( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -222,12 +218,12 @@ public BaseClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggerResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -236,11 +232,9 @@ public BaseClientHttpResponse update( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -293,11 +287,9 @@ public BaseClientHttpResponse delete( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -339,12 +331,12 @@ public BaseClientHttpResponse> listEvents( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetTriggerEventsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerEventsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerEventsResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -353,11 +345,9 @@ public BaseClientHttpResponse> listEvents( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -396,12 +386,12 @@ public BaseClientHttpResponse listWorkflows( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerWorkflowsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerWorkflowsResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -410,11 +400,9 @@ public BaseClientHttpResponse listWorkflows( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -461,12 +449,12 @@ public BaseClientHttpResponse updateWorkflows( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerWorkflowsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerWorkflowsResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -475,11 +463,9 @@ public BaseClientHttpResponse updateWorkflows( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -518,12 +504,12 @@ public BaseClientHttpResponse listWebhooks( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerWebhooksResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerWebhooksResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -532,11 +518,9 @@ public BaseClientHttpResponse listWebhooks( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -583,12 +567,12 @@ public BaseClientHttpResponse updateWebhooks( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetTriggerWebhooksResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetTriggerWebhooksResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -597,11 +581,9 @@ public BaseClientHttpResponse updateWebhooks( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/filestash/AsyncRawFileStashClient.java b/src/main/java/com/pipedream/api/resources/filestash/AsyncRawFileStashClient.java index aa73f5d..af09992 100644 --- a/src/main/java/com/pipedream/api/resources/filestash/AsyncRawFileStashClient.java +++ b/src/main/java/com/pipedream/api/resources/filestash/AsyncRawFileStashClient.java @@ -50,7 +50,8 @@ public CompletableFuture> downloadFile( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("file_stash/download"); + .addPathSegments("file_stash") + .addPathSegments("download"); QueryStringMapper.addQueryParameter(httpUrl, "s3_key", request.getS3Key(), false); Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) @@ -82,11 +83,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/filestash/RawFileStashClient.java b/src/main/java/com/pipedream/api/resources/filestash/RawFileStashClient.java index 2bd5052..e8dd8e7 100644 --- a/src/main/java/com/pipedream/api/resources/filestash/RawFileStashClient.java +++ b/src/main/java/com/pipedream/api/resources/filestash/RawFileStashClient.java @@ -46,7 +46,8 @@ public BaseClientHttpResponse downloadFile( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("file_stash/download"); + .addPathSegments("file_stash") + .addPathSegments("download"); QueryStringMapper.addQueryParameter(httpUrl, "s3_key", request.getS3Key(), false); Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl.build()) @@ -73,11 +74,9 @@ public BaseClientHttpResponse downloadFile( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/oauthtokens/AsyncRawOauthTokensClient.java b/src/main/java/com/pipedream/api/resources/oauthtokens/AsyncRawOauthTokensClient.java index a922464..1632abd 100644 --- a/src/main/java/com/pipedream/api/resources/oauthtokens/AsyncRawOauthTokensClient.java +++ b/src/main/java/com/pipedream/api/resources/oauthtokens/AsyncRawOauthTokensClient.java @@ -72,19 +72,16 @@ public CompletableFuture> creat @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue( - responseBody.string(), CreateOAuthTokenResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateOAuthTokenResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/oauthtokens/RawOauthTokensClient.java b/src/main/java/com/pipedream/api/resources/oauthtokens/RawOauthTokensClient.java index 23a1d85..9e8e254 100644 --- a/src/main/java/com/pipedream/api/resources/oauthtokens/RawOauthTokensClient.java +++ b/src/main/java/com/pipedream/api/resources/oauthtokens/RawOauthTokensClient.java @@ -65,17 +65,15 @@ public BaseClientHttpResponse create( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateOAuthTokenResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateOAuthTokenResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/projects/AsyncRawProjectsClient.java b/src/main/java/com/pipedream/api/resources/projects/AsyncRawProjectsClient.java index 2c9dffd..ec09065 100644 --- a/src/main/java/com/pipedream/api/resources/projects/AsyncRawProjectsClient.java +++ b/src/main/java/com/pipedream/api/resources/projects/AsyncRawProjectsClient.java @@ -98,9 +98,10 @@ public CompletableFuture>> li @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListProjectsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListProjectsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListProjectsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); ProjectsListRequest nextRequest = ProjectsListRequest.builder() @@ -122,7 +123,6 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 404: @@ -139,11 +139,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -197,12 +195,12 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Project.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Project.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -212,11 +210,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -263,12 +259,12 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Project.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Project.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -278,11 +274,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -342,11 +336,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -408,12 +400,12 @@ public CompletableFuture> update( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Project.class), response)); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Project.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -423,11 +415,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -504,11 +494,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -538,7 +526,8 @@ public CompletableFuture> retrieveIn .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("projects/info") + .addPathSegments("projects") + .addPathSegments("info") .build(); Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -555,13 +544,13 @@ public CompletableFuture> retrieveIn @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ProjectInfoResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProjectInfoResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -571,11 +560,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/projects/RawProjectsClient.java b/src/main/java/com/pipedream/api/resources/projects/RawProjectsClient.java index 2eee1a9..f3dd810 100644 --- a/src/main/java/com/pipedream/api/resources/projects/RawProjectsClient.java +++ b/src/main/java/com/pipedream/api/resources/projects/RawProjectsClient.java @@ -90,9 +90,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { ListProjectsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ListProjectsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ListProjectsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); ProjectsListRequest nextRequest = ProjectsListRequest.builder() .from(request) @@ -105,7 +106,6 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 404: @@ -118,11 +118,9 @@ public BaseClientHttpResponse> list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -163,11 +161,11 @@ public BaseClientHttpResponse create(CreateProjectOpts request, Request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Project.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Project.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -176,11 +174,9 @@ public BaseClientHttpResponse create(CreateProjectOpts request, Request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -214,11 +210,11 @@ public BaseClientHttpResponse retrieve(String projectId, RequestOptions } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Project.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Project.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -227,11 +223,9 @@ public BaseClientHttpResponse retrieve(String projectId, RequestOptions } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -277,11 +271,9 @@ public BaseClientHttpResponse delete(String projectId, RequestOptions requ } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -331,11 +323,11 @@ public BaseClientHttpResponse update( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Project.class), response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Project.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -344,11 +336,9 @@ public BaseClientHttpResponse update( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -408,11 +398,9 @@ public BaseClientHttpResponse updateLogo( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -433,7 +421,8 @@ public BaseClientHttpResponse retrieveInfo(RequestOptions r .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("projects/info") + .addPathSegments("projects") + .addPathSegments("info") .build(); Request okhttpRequest = new Request.Builder() .url(httpUrl) @@ -447,12 +436,11 @@ public BaseClientHttpResponse retrieveInfo(RequestOptions r } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ProjectInfoResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ProjectInfoResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -461,11 +449,9 @@ public BaseClientHttpResponse retrieveInfo(RequestOptions r } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/tokens/AsyncRawTokensClient.java b/src/main/java/com/pipedream/api/resources/tokens/AsyncRawTokensClient.java index 5ab836b..49f9aef 100644 --- a/src/main/java/com/pipedream/api/resources/tokens/AsyncRawTokensClient.java +++ b/src/main/java/com/pipedream/api/resources/tokens/AsyncRawTokensClient.java @@ -78,13 +78,13 @@ public CompletableFuture> create( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTokenResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTokenResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -94,11 +94,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -151,13 +149,13 @@ public CompletableFuture> validate @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ValidateTokenResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ValidateTokenResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -167,11 +165,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/tokens/RawTokensClient.java b/src/main/java/com/pipedream/api/resources/tokens/RawTokensClient.java index f9414f5..e5507d9 100644 --- a/src/main/java/com/pipedream/api/resources/tokens/RawTokensClient.java +++ b/src/main/java/com/pipedream/api/resources/tokens/RawTokensClient.java @@ -70,12 +70,11 @@ public BaseClientHttpResponse create(CreateTokenOpts reques } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CreateTokenResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, CreateTokenResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -84,11 +83,9 @@ public BaseClientHttpResponse create(CreateTokenOpts reques } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -128,12 +125,11 @@ public BaseClientHttpResponse validate( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ValidateTokenResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ValidateTokenResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -142,11 +138,9 @@ public BaseClientHttpResponse validate( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/triggers/AsyncRawTriggersClient.java b/src/main/java/com/pipedream/api/resources/triggers/AsyncRawTriggersClient.java index 714501d..8934f98 100644 --- a/src/main/java/com/pipedream/api/resources/triggers/AsyncRawTriggersClient.java +++ b/src/main/java/com/pipedream/api/resources/triggers/AsyncRawTriggersClient.java @@ -111,9 +111,10 @@ public CompletableFuture>> @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); TriggersListRequest nextRequest = TriggersListRequest.builder() @@ -135,7 +136,6 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 400: @@ -152,11 +152,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -216,13 +214,13 @@ public CompletableFuture> retrieve( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -232,11 +230,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -267,7 +263,8 @@ public CompletableFuture> configur .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("triggers/configure") + .addPathSegments("triggers") + .addPathSegments("configure") .build(); RequestBody body; try { @@ -292,13 +289,13 @@ public CompletableFuture> configur @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ConfigurePropResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ConfigurePropResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -308,11 +305,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -343,7 +338,8 @@ public CompletableFuture> reloadProp .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("triggers/props") + .addPathSegments("triggers") + .addPathSegments("props") .build(); RequestBody body; try { @@ -368,13 +364,13 @@ public CompletableFuture> reloadProp @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { future.complete(new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ReloadPropsResponse.class), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReloadPropsResponse.class), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -384,11 +380,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); @@ -419,7 +413,8 @@ public CompletableFuture> deploy( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("triggers/deploy") + .addPathSegments("triggers") + .addPathSegments("deploy") .build(); RequestBody body; try { @@ -444,13 +439,13 @@ public CompletableFuture> deploy( @Override public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { try (ResponseBody responseBody = response.body()) { + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { DeployTriggerResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeployTriggerResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeployTriggerResponse.class); future.complete(new BaseClientHttpResponse<>(parsedResponse.getData(), response)); return; } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { future.completeExceptionally(new TooManyRequestsError( @@ -460,11 +455,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/triggers/RawTriggersClient.java b/src/main/java/com/pipedream/api/resources/triggers/RawTriggersClient.java index 481ee85..f2cbc3d 100644 --- a/src/main/java/com/pipedream/api/resources/triggers/RawTriggersClient.java +++ b/src/main/java/com/pipedream/api/resources/triggers/RawTriggersClient.java @@ -103,9 +103,10 @@ public BaseClientHttpResponse> list( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentsResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentsResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentsResponse.class); Optional startingAfter = parsedResponse.getPageInfo().getEndCursor(); TriggersListRequest nextRequest = TriggersListRequest.builder() .from(request) @@ -118,7 +119,6 @@ public BaseClientHttpResponse> list( .body()), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { switch (response.code()) { case 400: @@ -131,11 +131,9 @@ public BaseClientHttpResponse> list( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -182,12 +180,12 @@ public BaseClientHttpResponse retrieve( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { GetComponentResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), GetComponentResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GetComponentResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -196,11 +194,9 @@ public BaseClientHttpResponse retrieve( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -222,7 +218,8 @@ public BaseClientHttpResponse configureProp( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("triggers/configure") + .addPathSegments("triggers") + .addPathSegments("configure") .build(); RequestBody body; try { @@ -244,12 +241,11 @@ public BaseClientHttpResponse configureProp( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ConfigurePropResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ConfigurePropResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -258,11 +254,9 @@ public BaseClientHttpResponse configureProp( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -284,7 +278,8 @@ public BaseClientHttpResponse reloadProps( .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("triggers/props") + .addPathSegments("triggers") + .addPathSegments("props") .build(); RequestBody body; try { @@ -306,12 +301,11 @@ public BaseClientHttpResponse reloadProps( } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { return new BaseClientHttpResponse<>( - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ReloadPropsResponse.class), - response); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ReloadPropsResponse.class), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -320,11 +314,9 @@ public BaseClientHttpResponse reloadProps( } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } @@ -345,7 +337,8 @@ public BaseClientHttpResponse deploy(DeployTriggerOpts request, Request .newBuilder() .addPathSegments("v1/connect") .addPathSegment(clientOptions.projectId()) - .addPathSegments("triggers/deploy") + .addPathSegments("triggers") + .addPathSegments("deploy") .build(); RequestBody body; try { @@ -367,12 +360,12 @@ public BaseClientHttpResponse deploy(DeployTriggerOpts request, Request } try (Response response = client.newCall(okhttpRequest).execute()) { ResponseBody responseBody = response.body(); + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; if (response.isSuccessful()) { DeployTriggerResponse parsedResponse = - ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeployTriggerResponse.class); + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, DeployTriggerResponse.class); return new BaseClientHttpResponse<>(parsedResponse.getData(), response); } - String responseBodyString = responseBody != null ? responseBody.string() : "{}"; try { if (response.code() == 429) { throw new TooManyRequestsError( @@ -381,11 +374,9 @@ public BaseClientHttpResponse deploy(DeployTriggerOpts request, Request } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/main/java/com/pipedream/api/resources/users/AsyncRawUsersClient.java b/src/main/java/com/pipedream/api/resources/users/AsyncRawUsersClient.java index c41f6f1..a1ad961 100644 --- a/src/main/java/com/pipedream/api/resources/users/AsyncRawUsersClient.java +++ b/src/main/java/com/pipedream/api/resources/users/AsyncRawUsersClient.java @@ -78,11 +78,9 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); future.completeExceptionally(new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response)); + "Error with status code " + response.code(), response.code(), errorBody, response)); return; } catch (IOException e) { future.completeExceptionally(new BaseClientException("Network error executing HTTP request", e)); diff --git a/src/main/java/com/pipedream/api/resources/users/RawUsersClient.java b/src/main/java/com/pipedream/api/resources/users/RawUsersClient.java index 097eaaf..15600a5 100644 --- a/src/main/java/com/pipedream/api/resources/users/RawUsersClient.java +++ b/src/main/java/com/pipedream/api/resources/users/RawUsersClient.java @@ -68,11 +68,9 @@ public BaseClientHttpResponse deleteExternalUser(String externalUserId, Re } catch (JsonProcessingException ignored) { // unable to map error response, throwing generic error } + Object errorBody = ObjectMappers.parseErrorBody(responseBodyString); throw new BaseClientApiException( - "Error with status code " + response.code(), - response.code(), - ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), - response); + "Error with status code " + response.code(), response.code(), errorBody, response); } catch (IOException e) { throw new BaseClientException("Network error executing HTTP request", e); } diff --git a/src/test/java/com/pipedream/api/StreamTest.java b/src/test/java/com/pipedream/api/StreamTest.java index 57130cb..212816c 100644 --- a/src/test/java/com/pipedream/api/StreamTest.java +++ b/src/test/java/com/pipedream/api/StreamTest.java @@ -9,6 +9,9 @@ import com.pipedream.api.core.Stream; import java.io.IOException; import java.io.StringReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -17,8 +20,9 @@ public final class StreamTest { @Test public void testJsonStream() { - List messages = List.of(Map.of("message", "hello"), Map.of("message", "world")); - List jsonStrings = messages.stream().map(StreamTest::mapToJson).collect(Collectors.toList()); + List> messages = + Arrays.asList(createMap("message", "hello"), createMap("message", "world")); + List jsonStrings = messages.stream().map(StreamTest::mapToJson).collect(Collectors.toList()); String input = String.join("\n", jsonStrings); StringReader jsonInput = new StringReader(input); Stream jsonStream = Stream.fromJson(Map.class, jsonInput); @@ -33,8 +37,8 @@ public void testJsonStream() { @Test public void testSseStream() { - List events = List.of(Map.of("event", "start"), Map.of("event", "end")); - List sseStrings = events.stream().map(StreamTest::mapToSse).collect(Collectors.toList()); + List> events = Arrays.asList(createMap("event", "start"), createMap("event", "end")); + List sseStrings = events.stream().map(StreamTest::mapToSse).collect(Collectors.toList()); String input = String.join("\n" + "\n", sseStrings); StringReader sseInput = new StringReader(input); Stream sseStream = Stream.fromSse(Map.class, sseInput); @@ -49,8 +53,9 @@ public void testSseStream() { @Test public void testSseStreamWithTerminator() { - List events = List.of(Map.of("message", "first"), Map.of("message", "second")); - List sseStrings = events.stream().map(StreamTest::mapToSse).collect(Collectors.toList()); + List> events = Arrays.asList(createMap("message", "first"), createMap("message", "second")); + List sseStrings = + new ArrayList<>(events.stream().map(StreamTest::mapToSse).collect(Collectors.toList())); sseStrings.add("data: [DONE]"); String input = String.join("\n" + "\n", sseStrings); StringReader sseInput = new StringReader(input); @@ -83,4 +88,10 @@ private static String mapToJson(Map map) { private static String mapToSse(Map map) { return "data: " + mapToJson(map); } + + private static Map createMap(String key, String value) { + Map map = new HashMap<>(); + map.put(key, value); + return map; + } }