From eade748ee19fa6620d452b7c2438edd5ed98d869 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Tue, 15 Aug 2023 13:18:40 +0000 Subject: [PATCH] Release 0.0.8 --- build.gradle | 2 +- .../java/com/squidex/api/AccessToken.java | 37 --- .../java/com/squidex/api/AuthInterceptor.java | 84 ------- .../com/squidex/api/InMemoryTokenStore.java | 20 -- .../squidex/api/SquidexApiClientBuilder.java | 102 +-------- src/main/java/com/squidex/api/TokenStore.java | 10 - .../java/com/squidex/api/core/ApiError.java | 25 +++ .../com/squidex/api/core/ClientOptions.java | 15 +- .../api/resources/apps/AppsClient.java | 212 ++++++++++++------ .../api/resources/assets/AssetsClient.java | 116 ++++++---- .../api/resources/backups/BackupsClient.java | 44 ++-- .../resources/comments/CommentsClient.java | 32 ++- .../resources/contents/ContentsClient.java | 110 ++++++--- .../diagnostics/DiagnosticsClient.java | 15 +- .../eventconsumers/EventConsumersClient.java | 26 ++- .../api/resources/history/HistoryClient.java | 14 +- .../resources/languages/LanguagesClient.java | 8 +- .../api/resources/news/NewsClient.java | 8 +- .../notifications/NotificationsClient.java | 14 +- .../api/resources/ping/PingClient.java | 20 +- .../api/resources/plans/PlansClient.java | 26 ++- .../api/resources/rules/RulesClient.java | 116 ++++++---- .../api/resources/schemas/SchemasClient.java | 188 +++++++++++----- .../api/resources/search/SearchClient.java | 8 +- .../statistics/StatisticsClient.java | 44 ++-- .../api/resources/teams/TeamsClient.java | 50 +++-- .../resources/templates/TemplatesClient.java | 14 +- .../translations/TranslationsClient.java | 8 +- .../usermanagement/UserManagementClient.java | 44 ++-- .../api/resources/users/UsersClient.java | 26 ++- src/test/java/com/squidex/api/TestClient.java | 8 + 31 files changed, 820 insertions(+), 626 deletions(-) delete mode 100644 src/main/java/com/squidex/api/AccessToken.java delete mode 100644 src/main/java/com/squidex/api/AuthInterceptor.java delete mode 100644 src/main/java/com/squidex/api/InMemoryTokenStore.java delete mode 100644 src/main/java/com/squidex/api/TokenStore.java create mode 100644 src/main/java/com/squidex/api/core/ApiError.java create mode 100644 src/test/java/com/squidex/api/TestClient.java diff --git a/build.gradle b/build.gradle index b020d5d..d933c91 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ publishing { maven(MavenPublication) { groupId = 'io.squidex' artifactId = 'squidex' - version = '0.0.7' + version = '0.0.8' from components.java } } diff --git a/src/main/java/com/squidex/api/AccessToken.java b/src/main/java/com/squidex/api/AccessToken.java deleted file mode 100644 index 3a023d3..0000000 --- a/src/main/java/com/squidex/api/AccessToken.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.squidex.api; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.time.Instant; - -public final class AccessToken { - private final String accessToken; - private final int expiresIn; - private final Instant expiresAt; - - @JsonCreator() - public AccessToken( - @JsonProperty("access_token")String accessToken, - @JsonProperty("expires_in")int expiresIn) { - this.accessToken = accessToken; - this.expiresIn = expiresIn; - this.expiresAt = Instant.now().plusSeconds(expiresIn); - } - - - public String getAccessToken() { - return accessToken; - } - - - public int getExpiresIn() { - return expiresIn; - } - - @JsonIgnore() - public Instant getExpiresAt() { - return expiresAt; - } -} diff --git a/src/main/java/com/squidex/api/AuthInterceptor.java b/src/main/java/com/squidex/api/AuthInterceptor.java deleted file mode 100644 index 497ee48..0000000 --- a/src/main/java/com/squidex/api/AuthInterceptor.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.squidex.api; - -import com.squidex.api.core.Environment; -import com.squidex.api.core.ObjectMappers; -import okhttp3.*; -import org.jetbrains.annotations.NotNull; - -import java.io.IOException; -import java.time.Instant; -import java.util.Objects; - -public final class AuthInterceptor implements Interceptor { - private final Environment environment; - private final String clientId; - private final String clientSecret; - private final TokenStore tokenStore; - private final OkHttpClient httpClient; - - public AuthInterceptor(OkHttpClient httpClient, Environment environment, String clientId, String clientSecret, TokenStore tokenStore) { - this.httpClient = httpClient; - this.environment = environment; - this.clientId = clientId; - this.clientSecret = clientSecret; - this.tokenStore = tokenStore; - } - - @NotNull - @Override - public Response intercept(@NotNull Chain chain) throws IOException { - Request originalRequest = chain.request(); - - AccessToken token = this.tokenStore.get(); - if (token != null && token.getExpiresAt().isBefore(Instant.now())) { - // The token has been expired, therefore also remove it from the store for other calls. - token = null; - this.tokenStore.clear(); - } - - if (token == null) { - token = acquireToken(); - this.tokenStore.set(token); - } - - Request requestWithHeader = originalRequest.newBuilder() - .header("Authorization", "Bearer %s".formatted(token.getAccessToken())) - .build(); - - Response response = chain.proceed(requestWithHeader); - if (response.code() == 401) { - this.tokenStore.clear(); - - return intercept(chain); - } - - return response; - } - - private AccessToken acquireToken() throws IOException { - RequestBody formBody = new FormBody.Builder() - .add("grant_type", "client_credentials") - .add("client_id", this.clientId) - .add("client_secret", this.clientSecret) - .add("scope", "squidex-api") - .build(); - - HttpUrl tokenUrl = Objects.requireNonNull(HttpUrl.parse(this.environment.getUrl())) - .newBuilder() - .addPathSegments("identity-server/connect/token") - .build(); - - Request tokenRequest = new Request.Builder() - .url(tokenUrl.url()) - .post(formBody) - .build(); - - AccessToken token; - try (Response response = this.httpClient.newCall(tokenRequest).execute()) { - assert response.body() != null; - token = ObjectMappers.JSON_MAPPER.readValue(response.body().string(), AccessToken.class); - } - - return token; - } -} \ No newline at end of file diff --git a/src/main/java/com/squidex/api/InMemoryTokenStore.java b/src/main/java/com/squidex/api/InMemoryTokenStore.java deleted file mode 100644 index 1d074e9..0000000 --- a/src/main/java/com/squidex/api/InMemoryTokenStore.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.squidex.api; - -public class InMemoryTokenStore implements TokenStore { - private AccessToken currentToken; - - @Override - public AccessToken get() { - return this.currentToken; - } - - @Override - public void set(AccessToken token) { - this.currentToken = token; - } - - @Override - public void clear() { - this.currentToken = null; - } -} diff --git a/src/main/java/com/squidex/api/SquidexApiClientBuilder.java b/src/main/java/com/squidex/api/SquidexApiClientBuilder.java index 6d4bced..fc6ea73 100644 --- a/src/main/java/com/squidex/api/SquidexApiClientBuilder.java +++ b/src/main/java/com/squidex/api/SquidexApiClientBuilder.java @@ -2,21 +2,16 @@ import com.squidex.api.core.ClientOptions; import com.squidex.api.core.Environment; -import okhttp3.OkHttpClient; - -import javax.net.ssl.*; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; public final class SquidexApiClientBuilder { - private final ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); + private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder(); private Environment environment = Environment.DEFAULT; - private String clientId; - private String clientSecret; - private TokenStore tokenStore; - private OkHttpClient httpClient; - private boolean trustAllCerts; + + public SquidexApiClientBuilder token(String token) { + this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token); + return this; + } public SquidexApiClientBuilder environment(Environment environment) { this.environment = environment; @@ -28,96 +23,13 @@ public SquidexApiClientBuilder url(String url) { return this; } - public SquidexApiClientBuilder clientId(String clientId) { - this.clientId = clientId; - return this; - } - - public String clientId() { - return this.clientId; - } - - public SquidexApiClientBuilder clientSecret(String clientSecret) { - this.clientSecret = clientSecret; - return this; - } - - public String clientSecret() { - return this.clientSecret; - } - - public SquidexApiClientBuilder tokenStore(TokenStore tokenStore) { - this.tokenStore = tokenStore; - return this; - } - - public SquidexApiClientBuilder httpClient(OkHttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - public SquidexApiClientBuilder appName(String appName) { - this.clientOptionsBuilder.appName(appName); - return this; - } - - public SquidexApiClientBuilder trustAllCerts() { - this.trustAllCerts = true; + clientOptionsBuilder.appName(appName); return this; } public SquidexApiClient build() { clientOptionsBuilder.environment(this.environment); - - if (this.tokenStore == null) { - this.tokenStore = new InMemoryTokenStore(); - } - - if (this.httpClient == null) { - this.httpClient = new OkHttpClient(); - } - - if (this.trustAllCerts) { - X509TrustManager trustAllCerts = new X509TrustManager() { - @Override - public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) { - } - - @Override - public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) { - } - - @Override - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return new java.security.cert.X509Certificate[] {}; - } - }; - - try { - SSLContext sslContext = SSLContext.getInstance("SSL"); - sslContext.init(null, new TrustManager[] { trustAllCerts }, new java.security.SecureRandom()); - - this.httpClient = this.httpClient.newBuilder() - .sslSocketFactory(sslContext.getSocketFactory(), trustAllCerts) - .build(); - } catch (NoSuchAlgorithmException | KeyManagementException e) { - throw new RuntimeException(e); - } - } - - AuthInterceptor interceptor = new AuthInterceptor( - this.httpClient, - this.environment, - this.clientId, - this.clientSecret, - this.tokenStore); - - this.httpClient = this.httpClient.newBuilder() - .addInterceptor(interceptor) - .build(); - - clientOptionsBuilder.httpClient(this.httpClient); - return new SquidexApiClient(clientOptionsBuilder.build()); } } diff --git a/src/main/java/com/squidex/api/TokenStore.java b/src/main/java/com/squidex/api/TokenStore.java deleted file mode 100644 index 4b95ef6..0000000 --- a/src/main/java/com/squidex/api/TokenStore.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.squidex.api; - -public interface TokenStore { - AccessToken get(); - - void set(AccessToken token); - - void clear(); -} - diff --git a/src/main/java/com/squidex/api/core/ApiError.java b/src/main/java/com/squidex/api/core/ApiError.java new file mode 100644 index 0000000..8a38adc --- /dev/null +++ b/src/main/java/com/squidex/api/core/ApiError.java @@ -0,0 +1,25 @@ +package com.squidex.api.core; + +public final class ApiError extends RuntimeException { + private final int statusCode; + + private final Object body; + + public ApiError(int statusCode, Object body) { + this.statusCode = statusCode; + this.body = body; + } + + public int statusCode() { + return this.statusCode; + } + + public Object body() { + return this.body; + } + + @Override + public String toString() { + return "ApiError{" + "statusCode: " + statusCode + ", body: " + body + "}"; + } +} diff --git a/src/main/java/com/squidex/api/core/ClientOptions.java b/src/main/java/com/squidex/api/core/ClientOptions.java index 3398069..06f542c 100644 --- a/src/main/java/com/squidex/api/core/ClientOptions.java +++ b/src/main/java/com/squidex/api/core/ClientOptions.java @@ -29,7 +29,7 @@ private ClientOptions( "X-Fern-SDK-Name", "com.squidex.fern:api-sdk", "X-Fern-SDK-Version", - "0.0.7", + "0.0.8", "X-Fern-Language", "JAVA")); this.headerSuppliers = headerSuppliers; @@ -67,8 +67,6 @@ public static Builder builder() { public static final class Builder { private Environment environment; - private OkHttpClient httpClient; - private final Map headers = new HashMap<>(); private final Map> headerSuppliers = new HashMap<>(); @@ -95,17 +93,8 @@ public Builder appName(String appName) { return this; } - public Builder httpClient(OkHttpClient httpClient) { - this.httpClient = httpClient; - return this; - } - public ClientOptions build() { - if (this.httpClient == null) { - this.httpClient = new OkHttpClient(); - } - - return new ClientOptions(environment, headers, headerSuppliers, this.httpClient, this.appName); + return new ClientOptions(environment, headers, headerSuppliers, new OkHttpClient(), this.appName); } } } diff --git a/src/main/java/com/squidex/api/resources/apps/AppsClient.java b/src/main/java/com/squidex/api/resources/apps/AppsClient.java index c5767aa..e3acba7 100644 --- a/src/main/java/com/squidex/api/resources/apps/AppsClient.java +++ b/src/main/java/com/squidex/api/resources/apps/AppsClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.apps; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -28,6 +29,7 @@ import com.squidex.api.types.RolesDto; import com.squidex.api.types.WorkflowsDto; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.List; @@ -69,8 +71,10 @@ public AssetScriptsDto getAssetScripts(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetScriptsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -127,8 +131,10 @@ public AssetScriptsDto putAssetScripts(UpdateAssetScriptsDto request, RequestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetScriptsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -155,8 +161,10 @@ public ClientsDto getClients(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ClientsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -193,8 +201,10 @@ public ClientsDto postClient(CreateClientDto request, RequestOptions requestOpti if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ClientsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -246,8 +256,10 @@ public ClientsDto putClient(String id, UpdateClientDto request, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ClientsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -275,8 +287,10 @@ public ClientsDto deleteClient(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ClientsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -303,8 +317,10 @@ public ContributorsDto getContributors(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -338,8 +354,10 @@ public ContributorsDto postContributor(AssignContributorDto request, RequestOpti if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -366,8 +384,10 @@ public ContributorsDto deleteMyself(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -395,8 +415,10 @@ public ContributorsDto deleteContributor(String id, RequestOptions requestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -423,8 +445,10 @@ public InputStream getImage(RequestOptions requestOptions) { if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -454,8 +478,10 @@ public AppDto uploadImage(File file, AppsUploadImageRequest request, RequestOpti if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -482,8 +508,10 @@ public AppDto deleteImage(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -510,8 +538,10 @@ public AppLanguagesDto getLanguages(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppLanguagesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -548,8 +578,10 @@ public AppLanguagesDto postLanguage(AddLanguageDto request, RequestOptions reque if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppLanguagesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -595,8 +627,10 @@ public AppLanguagesDto putLanguage(String language, UpdateLanguageDto request, R if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppLanguagesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -624,8 +658,10 @@ public AppLanguagesDto deleteLanguage(String language, RequestOptions requestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppLanguagesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -652,8 +688,10 @@ public RolesDto getRoles(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RolesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -690,8 +728,10 @@ public RolesDto postRole(AddRoleDto request, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RolesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -719,8 +759,10 @@ public List getPermissions(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -761,8 +803,10 @@ public RolesDto putRole(String roleName, UpdateRoleDto request, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RolesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -790,8 +834,10 @@ public RolesDto deleteRole(String roleName, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RolesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -817,8 +863,10 @@ public List getApps(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -856,8 +904,10 @@ public AppDto postApp(CreateAppDto request, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -885,8 +935,10 @@ public List getTeamApps(String team, RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -912,8 +964,10 @@ public AppDto getApp(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -954,8 +1008,10 @@ public AppDto putApp(UpdateAppDto request, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -980,8 +1036,10 @@ public void deleteApp(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1020,8 +1078,10 @@ public AppDto putAppTeam(TransferToTeamDto request, RequestOptions requestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1048,8 +1108,10 @@ public AppSettingsDto getSettings(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppSettingsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1093,8 +1155,10 @@ public AppSettingsDto putSettings(UpdateAppSettingsDto request, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AppSettingsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1121,8 +1185,10 @@ public WorkflowsDto getWorkflows(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), WorkflowsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1159,8 +1225,10 @@ public WorkflowsDto postWorkflow(AddWorkflowDto request, RequestOptions requestO if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), WorkflowsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1205,8 +1273,10 @@ public WorkflowsDto putWorkflow(String id, UpdateWorkflowDto request, RequestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), WorkflowsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1234,8 +1304,10 @@ public WorkflowsDto deleteWorkflow(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), WorkflowsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/assets/AssetsClient.java b/src/main/java/com/squidex/api/resources/assets/AssetsClient.java index 991b436..3ee960e 100644 --- a/src/main/java/com/squidex/api/resources/assets/AssetsClient.java +++ b/src/main/java/com/squidex/api/resources/assets/AssetsClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.assets; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -26,6 +27,7 @@ import com.squidex.api.types.AssetsDto; import com.squidex.api.types.BulkResultDto; import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.List; @@ -119,8 +121,10 @@ public InputStream getAssetContentBySlug( if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -189,8 +193,10 @@ public InputStream getAssetContent(String id, AssetsGetAssetContentRequest reque if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -224,8 +230,10 @@ public AssetFoldersDto getAssetFolders(AssetsGetAssetFoldersRequest request, Req if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetFoldersDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -265,8 +273,10 @@ public AssetFolderDto postAssetFolder(CreateAssetFolderDto request, RequestOptio if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetFolderDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -304,8 +314,10 @@ public AssetFolderDto putAssetFolder(String id, RenameAssetFolderDto request, Re if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetFolderDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -332,8 +344,10 @@ public void deleteAssetFolder(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -374,8 +388,10 @@ public AssetFolderDto putAssetFolderParent(String id, MoveAssetFolderDto request if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetFolderDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -403,8 +419,10 @@ public Map getTags(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -443,8 +461,10 @@ public Map putTag(String name, RenameTagDto request, RequestOpt return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -500,8 +520,10 @@ public AssetsDto getAssets(AssetsGetAssetsRequest request, RequestOptions reques if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -540,8 +562,10 @@ public AssetDto postAsset(File file, AssetsPostAssetRequest request, RequestOpti if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -583,8 +607,10 @@ public AssetsDto getAssetsPost(AssetsGetAssetsPostRequest request, RequestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -612,8 +638,10 @@ public AssetDto getAsset(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -651,8 +679,10 @@ public AssetDto postUpsertAsset( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -704,8 +734,10 @@ public AssetDto putAsset(String id, AnnotateAssetDto request, RequestOptions req if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -740,8 +772,10 @@ public void deleteAsset(String id, AssetsDeleteAssetRequest request, RequestOpti if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -790,8 +824,10 @@ public List bulkUpdateAssets(BulkUpdateAssetsDto request, Request return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -824,8 +860,10 @@ public AssetDto putAssetContent( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -866,8 +904,10 @@ public AssetDto putAssetParent(String id, MoveAssetDto request, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), AssetDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/backups/BackupsClient.java b/src/main/java/com/squidex/api/resources/backups/BackupsClient.java index f4f4396..75906fc 100644 --- a/src/main/java/com/squidex/api/resources/backups/BackupsClient.java +++ b/src/main/java/com/squidex/api/resources/backups/BackupsClient.java @@ -1,5 +1,6 @@ package com.squidex.api.resources.backups; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -7,6 +8,7 @@ import com.squidex.api.resources.backups.requests.RestoreRequestDto; import com.squidex.api.types.BackupJobsDto; import com.squidex.api.types.RestoreJobDto; +import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -47,8 +49,10 @@ public InputStream getBackupContent(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -75,8 +79,10 @@ public void deleteBackup(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -110,8 +116,10 @@ public InputStream getBackupContentV2( if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -138,8 +146,10 @@ public BackupJobsDto getBackups(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), BackupJobsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -165,8 +175,10 @@ public void postBackup(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -191,8 +203,10 @@ public RestoreJobDto getRestoreJob(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RestoreJobDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -230,8 +244,10 @@ public void postRestoreJob(RestoreRequestDto request, RequestOptions requestOpti if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/comments/CommentsClient.java b/src/main/java/com/squidex/api/resources/comments/CommentsClient.java index d2c87e7..25dc5c1 100644 --- a/src/main/java/com/squidex/api/resources/comments/CommentsClient.java +++ b/src/main/java/com/squidex/api/resources/comments/CommentsClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.comments; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -8,6 +9,7 @@ import com.squidex.api.types.CommentDto; import com.squidex.api.types.CommentsDto; import com.squidex.api.types.UpsertCommentDto; +import java.io.IOException; import java.util.List; import java.util.Optional; import okhttp3.Headers; @@ -50,8 +52,10 @@ public List getWatchingUsers(Optional resource, RequestOptions r return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -84,8 +88,10 @@ public CommentsDto getComments( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CommentsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -120,8 +126,10 @@ public CommentDto postComment(String commentsId, UpsertCommentDto request, Reque if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CommentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -158,8 +166,10 @@ public void putComment( if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -187,8 +197,10 @@ public void deleteComment(String commentsId, String commentId, RequestOptions re if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/contents/ContentsClient.java b/src/main/java/com/squidex/api/resources/contents/ContentsClient.java index 5e11ad7..f68f936 100644 --- a/src/main/java/com/squidex/api/resources/contents/ContentsClient.java +++ b/src/main/java/com/squidex/api/resources/contents/ContentsClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.contents; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -24,6 +25,7 @@ import com.squidex.api.types.BulkResultDto; import com.squidex.api.types.ContentDto; import com.squidex.api.types.ContentsDto; +import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.List; @@ -103,8 +105,10 @@ public ContentsDto getContents(String schema, ContentsGetContentsRequest request if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -155,8 +159,10 @@ public ContentDto postContent(String schema, ContentsPostContentRequest request, if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -210,8 +216,10 @@ public ContentsDto getContentsPost( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -254,8 +262,10 @@ public ContentDto getContent( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -308,8 +318,10 @@ public ContentDto postUpsertContent( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -353,8 +365,10 @@ public ContentDto putContent( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -398,8 +412,10 @@ public ContentDto patchContent( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -435,8 +451,10 @@ public void deleteContent( if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -464,8 +482,10 @@ public void getContentValidity(String schema, String id, RequestOptions requestO if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -516,8 +536,10 @@ public ContentsDto getReferences( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -568,8 +590,10 @@ public ContentsDto getReferencing( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -612,8 +636,10 @@ public InputStream getContentVersion( if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -661,8 +687,10 @@ public List postContents(String schema, ImportContentsDto request return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -720,8 +748,10 @@ public List bulkUpdateContents( return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -774,8 +804,10 @@ public ContentDto putContentStatus( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -813,8 +845,10 @@ public ContentDto deleteContentStatus( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -852,8 +886,10 @@ public ContentDto createDraft( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -891,8 +927,10 @@ public ContentDto deleteVersion( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContentDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/diagnostics/DiagnosticsClient.java b/src/main/java/com/squidex/api/resources/diagnostics/DiagnosticsClient.java index 2cc8518..1efd00a 100644 --- a/src/main/java/com/squidex/api/resources/diagnostics/DiagnosticsClient.java +++ b/src/main/java/com/squidex/api/resources/diagnostics/DiagnosticsClient.java @@ -1,7 +1,10 @@ package com.squidex.api.resources.diagnostics; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; +import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; +import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.Request; @@ -33,8 +36,10 @@ public void getDump(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -58,8 +63,10 @@ public void getGcDump(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/eventconsumers/EventConsumersClient.java b/src/main/java/com/squidex/api/resources/eventconsumers/EventConsumersClient.java index 70d38e9..beff49d 100644 --- a/src/main/java/com/squidex/api/resources/eventconsumers/EventConsumersClient.java +++ b/src/main/java/com/squidex/api/resources/eventconsumers/EventConsumersClient.java @@ -1,10 +1,12 @@ package com.squidex.api.resources.eventconsumers; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.types.EventConsumerDto; import com.squidex.api.types.EventConsumersDto; +import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.Request; @@ -37,8 +39,10 @@ public EventConsumersDto getEventConsumers(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), EventConsumersDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -65,8 +69,10 @@ public EventConsumerDto startEventConsumer(String consumerName, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), EventConsumerDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -93,8 +99,10 @@ public EventConsumerDto stopEventConsumer(String consumerName, RequestOptions re if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), EventConsumerDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -121,8 +129,10 @@ public EventConsumerDto resetEventConsumer(String consumerName, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), EventConsumerDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/history/HistoryClient.java b/src/main/java/com/squidex/api/resources/history/HistoryClient.java index 209bd09..ad19c53 100644 --- a/src/main/java/com/squidex/api/resources/history/HistoryClient.java +++ b/src/main/java/com/squidex/api/resources/history/HistoryClient.java @@ -1,12 +1,14 @@ package com.squidex.api.resources.history; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.resources.history.requests.HistoryGetAppHistoryRequest; import com.squidex.api.resources.history.requests.HistoryGetTeamHistoryRequest; import com.squidex.api.types.HistoryEventDto; +import java.io.IOException; import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -48,8 +50,10 @@ public List getAppHistory(HistoryGetAppHistoryRequest request, return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -82,8 +86,10 @@ public List getTeamHistory( return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/languages/LanguagesClient.java b/src/main/java/com/squidex/api/resources/languages/LanguagesClient.java index 3629a63..ff6437b 100644 --- a/src/main/java/com/squidex/api/resources/languages/LanguagesClient.java +++ b/src/main/java/com/squidex/api/resources/languages/LanguagesClient.java @@ -1,10 +1,12 @@ package com.squidex.api.resources.languages; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.types.LanguageDto; +import java.io.IOException; import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -39,8 +41,10 @@ public List getLanguages(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/news/NewsClient.java b/src/main/java/com/squidex/api/resources/news/NewsClient.java index 56a70e7..acba1a1 100644 --- a/src/main/java/com/squidex/api/resources/news/NewsClient.java +++ b/src/main/java/com/squidex/api/resources/news/NewsClient.java @@ -1,10 +1,12 @@ package com.squidex.api.resources.news; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.resources.news.requests.NewsGetNewsRequest; import com.squidex.api.types.FeaturesDto; +import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.Request; @@ -42,8 +44,10 @@ public FeaturesDto getNews(NewsGetNewsRequest request, RequestOptions requestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), FeaturesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/notifications/NotificationsClient.java b/src/main/java/com/squidex/api/resources/notifications/NotificationsClient.java index 377bf15..ac060d1 100644 --- a/src/main/java/com/squidex/api/resources/notifications/NotificationsClient.java +++ b/src/main/java/com/squidex/api/resources/notifications/NotificationsClient.java @@ -1,10 +1,12 @@ package com.squidex.api.resources.notifications; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.resources.notifications.requests.NotificationsGetNotificationsRequest; import com.squidex.api.types.CommentsDto; +import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.Request; @@ -45,8 +47,10 @@ public CommentsDto getNotifications( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CommentsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -73,8 +77,10 @@ public void deleteComment(String userId, String commentId, RequestOptions reques if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/ping/PingClient.java b/src/main/java/com/squidex/api/resources/ping/PingClient.java index 176dcfa..3437d03 100644 --- a/src/main/java/com/squidex/api/resources/ping/PingClient.java +++ b/src/main/java/com/squidex/api/resources/ping/PingClient.java @@ -1,9 +1,11 @@ package com.squidex.api.resources.ping; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; +import java.io.IOException; import java.util.Map; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -38,8 +40,10 @@ public Map getInfo(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -63,8 +67,10 @@ public void getPing(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -89,8 +95,10 @@ public void getAppPing(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/plans/PlansClient.java b/src/main/java/com/squidex/api/resources/plans/PlansClient.java index 00c27c6..50abfd9 100644 --- a/src/main/java/com/squidex/api/resources/plans/PlansClient.java +++ b/src/main/java/com/squidex/api/resources/plans/PlansClient.java @@ -1,11 +1,13 @@ package com.squidex.api.resources.plans; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.types.ChangePlanDto; import com.squidex.api.types.PlanChangedDto; import com.squidex.api.types.PlansDto; +import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.MediaType; @@ -42,8 +44,10 @@ public PlansDto getPlans(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), PlansDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -77,8 +81,10 @@ public PlanChangedDto putPlan(ChangePlanDto request, RequestOptions requestOptio if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), PlanChangedDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -105,8 +111,10 @@ public PlansDto getTeamPlans(String team, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), PlansDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -140,8 +148,10 @@ public PlanChangedDto putTeamPlan(String team, ChangePlanDto request, RequestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), PlanChangedDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/rules/RulesClient.java b/src/main/java/com/squidex/api/resources/rules/RulesClient.java index 22aa278..7d99939 100644 --- a/src/main/java/com/squidex/api/resources/rules/RulesClient.java +++ b/src/main/java/com/squidex/api/resources/rules/RulesClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.rules; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -13,6 +14,7 @@ import com.squidex.api.types.RuleEventsDto; import com.squidex.api.types.RulesDto; import com.squidex.api.types.SimulatedRuleEventsDto; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -51,8 +53,10 @@ public Map getActions(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -79,8 +83,10 @@ public RulesDto getRules(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RulesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -114,8 +120,10 @@ public RuleDto postRule(CreateRuleDto request, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RuleDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -141,8 +149,10 @@ public void deleteRuleRun(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -191,8 +201,10 @@ public RuleDto putRule(String id, UpdateRuleDto request, RequestOptions requestO if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RuleDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -219,8 +231,10 @@ public void deleteRule(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -249,8 +263,10 @@ public RuleDto enableRule(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RuleDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -279,8 +295,10 @@ public RuleDto disableRule(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RuleDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -308,8 +326,10 @@ public void triggerRule(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -342,8 +362,10 @@ public void putRuleRun(String id, RulesPutRuleRunRequest request, RequestOptions if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -371,8 +393,10 @@ public void deleteRuleEvents(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -406,8 +430,10 @@ public SimulatedRuleEventsDto simulatePost(CreateRuleDto request, RequestOptions if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SimulatedRuleEventsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -436,8 +462,10 @@ public SimulatedRuleEventsDto simulateGet(String id, RequestOptions requestOptio if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SimulatedRuleEventsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -474,8 +502,10 @@ public RuleEventsDto getEvents(RulesGetEventsRequest request, RequestOptions req if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), RuleEventsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -501,8 +531,10 @@ public void deleteEvents(RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -529,8 +561,10 @@ public void putEvent(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -557,8 +591,10 @@ public void deleteEvent(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -584,8 +620,10 @@ public List getEventTypes(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -611,8 +649,10 @@ public Object getEventSchema(String type, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/schemas/SchemasClient.java b/src/main/java/com/squidex/api/resources/schemas/SchemasClient.java index 793760c..b5838f1 100644 --- a/src/main/java/com/squidex/api/resources/schemas/SchemasClient.java +++ b/src/main/java/com/squidex/api/resources/schemas/SchemasClient.java @@ -1,5 +1,6 @@ package com.squidex.api.resources.schemas; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -15,6 +16,7 @@ import com.squidex.api.types.SchemaScriptsDto; import com.squidex.api.types.SchemasDto; import com.squidex.api.types.UpdateFieldDto; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Headers; @@ -62,8 +64,10 @@ public SchemaDto postField(String schema, AddFieldDto request, RequestOptions re if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -101,8 +105,10 @@ public SchemaDto postNestedField(String schema, int parentId, AddFieldDto reques if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -146,8 +152,10 @@ public SchemaDto putSchemaUiFields(String schema, ConfigureUiFieldsDto request, if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -183,8 +191,10 @@ public SchemaDto putSchemaFieldOrdering(String schema, ReorderFieldsDto request, if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -223,8 +233,10 @@ public SchemaDto putNestedFieldOrdering( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -261,8 +273,10 @@ public SchemaDto putField(String schema, int id, UpdateFieldDto request, Request if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -292,8 +306,10 @@ public SchemaDto deleteField(String schema, int id, RequestOptions requestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -333,8 +349,10 @@ public SchemaDto putNestedField( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -366,8 +384,10 @@ public SchemaDto deleteNestedField(String schema, int parentId, int id, RequestO if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -398,8 +418,10 @@ public SchemaDto lockField(String schema, int id, RequestOptions requestOptions) if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -432,8 +454,10 @@ public SchemaDto lockNestedField(String schema, int parentId, int id, RequestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -464,8 +488,10 @@ public SchemaDto hideField(String schema, int id, RequestOptions requestOptions) if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -498,8 +524,10 @@ public SchemaDto hideNestedField(String schema, int parentId, int id, RequestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -530,8 +558,10 @@ public SchemaDto showField(String schema, int id, RequestOptions requestOptions) if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -564,8 +594,10 @@ public SchemaDto showNestedField(String schema, int parentId, int id, RequestOpt if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -596,8 +628,10 @@ public SchemaDto enableField(String schema, int id, RequestOptions requestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -630,8 +664,10 @@ public SchemaDto enableNestedField(String schema, int parentId, int id, RequestO if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -662,8 +698,10 @@ public SchemaDto disableField(String schema, int id, RequestOptions requestOptio if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -696,8 +734,10 @@ public SchemaDto disableNestedField(String schema, int parentId, int id, Request if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -724,8 +764,10 @@ public SchemasDto getSchemas(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemasDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -768,8 +810,10 @@ public SchemaDto postSchema(CreateSchemaDto request, RequestOptions requestOptio if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -797,8 +841,10 @@ public SchemaDto getSchema(String schema, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -856,8 +902,10 @@ public SchemaDto putSchema(String schema, UpdateSchemaDto request, RequestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -884,8 +932,10 @@ public void deleteSchema(String schema, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -929,8 +979,10 @@ public SchemaDto putSchemaSync(String schema, SynchronizeSchemaDto request, Requ if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -971,8 +1023,10 @@ public SchemaDto putCategory(String schema, ChangeCategoryDto request, RequestOp if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1008,8 +1062,10 @@ public SchemaDto putPreviewUrls(String schema, Map request, Requ if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1045,8 +1101,10 @@ public SchemaDto putScripts(String schema, SchemaScriptsDto request, RequestOpti if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1087,8 +1145,10 @@ public SchemaDto putRules(String schema, ConfigureFieldRulesDto request, Request if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1117,8 +1177,10 @@ public SchemaDto publishSchema(String schema, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -1147,8 +1209,10 @@ public SchemaDto unpublishSchema(String schema, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), SchemaDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/search/SearchClient.java b/src/main/java/com/squidex/api/resources/search/SearchClient.java index d7e59da..e08b4d9 100644 --- a/src/main/java/com/squidex/api/resources/search/SearchClient.java +++ b/src/main/java/com/squidex/api/resources/search/SearchClient.java @@ -1,11 +1,13 @@ package com.squidex.api.resources.search; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.resources.search.requests.SearchGetSearchResultsRequest; import com.squidex.api.types.SearchResultDto; +import java.io.IOException; import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -48,8 +50,10 @@ public List getSearchResults( return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/statistics/StatisticsClient.java b/src/main/java/com/squidex/api/resources/statistics/StatisticsClient.java index b5aa0e0..281578c 100644 --- a/src/main/java/com/squidex/api/resources/statistics/StatisticsClient.java +++ b/src/main/java/com/squidex/api/resources/statistics/StatisticsClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.statistics; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -8,6 +9,7 @@ import com.squidex.api.types.CurrentStorageDto; import com.squidex.api.types.LogDownloadDto; import com.squidex.api.types.StorageUsagePerDateDto; +import java.io.IOException; import java.util.List; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -43,8 +45,10 @@ public LogDownloadDto getLog(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), LogDownloadDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -73,8 +77,10 @@ public CallsUsageDtoDto getUsages(String fromDate, String toDate, RequestOptions if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CallsUsageDtoDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -104,8 +110,10 @@ public CallsUsageDtoDto getUsagesForTeam( if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CallsUsageDtoDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -132,8 +140,10 @@ public CurrentStorageDto getCurrentStorageSize(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CurrentStorageDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -160,8 +170,10 @@ public CurrentStorageDto getTeamCurrentStorageSizeForTeam(String team, RequestOp if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), CurrentStorageDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -191,8 +203,10 @@ public List getStorageSizes(String fromDate, String toDa return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -223,8 +237,10 @@ public List getStorageSizesForTeam( return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/teams/TeamsClient.java b/src/main/java/com/squidex/api/resources/teams/TeamsClient.java index dc9cca5..4712232 100644 --- a/src/main/java/com/squidex/api/resources/teams/TeamsClient.java +++ b/src/main/java/com/squidex/api/resources/teams/TeamsClient.java @@ -1,6 +1,7 @@ package com.squidex.api.resources.teams; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -9,6 +10,7 @@ import com.squidex.api.types.AssignContributorDto; import com.squidex.api.types.ContributorsDto; import com.squidex.api.types.TeamDto; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,8 +50,10 @@ public ContributorsDto getContributors(String team, RequestOptions requestOption if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -83,8 +87,10 @@ public ContributorsDto postContributor(String team, AssignContributorDto request if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -111,8 +117,10 @@ public ContributorsDto deleteMyself(String team, RequestOptions requestOptions) if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -140,8 +148,10 @@ public ContributorsDto deleteContributor(String team, String id, RequestOptions if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ContributorsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -167,8 +177,10 @@ public List getTeams(RequestOptions requestOptions) { return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -203,8 +215,10 @@ public TeamDto postTeam(CreateTeamDto request, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), TeamDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -230,8 +244,10 @@ public TeamDto getTeam(String team, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), TeamDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -267,8 +283,10 @@ public TeamDto putTeam(String team, UpdateTeamDto request, RequestOptions reques if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), TeamDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/templates/TemplatesClient.java b/src/main/java/com/squidex/api/resources/templates/TemplatesClient.java index c38cb69..882f159 100644 --- a/src/main/java/com/squidex/api/resources/templates/TemplatesClient.java +++ b/src/main/java/com/squidex/api/resources/templates/TemplatesClient.java @@ -1,10 +1,12 @@ package com.squidex.api.resources.templates; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.types.TemplateDetailsDto; import com.squidex.api.types.TemplatesDto; +import java.io.IOException; import okhttp3.Headers; import okhttp3.HttpUrl; import okhttp3.Request; @@ -37,8 +39,10 @@ public TemplatesDto getTemplates(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), TemplatesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -64,8 +68,10 @@ public TemplateDetailsDto getTemplate(String name, RequestOptions requestOptions if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), TemplateDetailsDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/translations/TranslationsClient.java b/src/main/java/com/squidex/api/resources/translations/TranslationsClient.java index b2532e2..cf79d4b 100644 --- a/src/main/java/com/squidex/api/resources/translations/TranslationsClient.java +++ b/src/main/java/com/squidex/api/resources/translations/TranslationsClient.java @@ -1,10 +1,12 @@ package com.squidex.api.resources.translations; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.resources.translations.requests.TranslateDto; import com.squidex.api.types.TranslationDto; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Headers; @@ -57,8 +59,10 @@ public TranslationDto postTranslation(TranslateDto request, RequestOptions reque if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), TranslationDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/usermanagement/UserManagementClient.java b/src/main/java/com/squidex/api/resources/usermanagement/UserManagementClient.java index 06a95f0..9810839 100644 --- a/src/main/java/com/squidex/api/resources/usermanagement/UserManagementClient.java +++ b/src/main/java/com/squidex/api/resources/usermanagement/UserManagementClient.java @@ -1,5 +1,6 @@ package com.squidex.api.resources.usermanagement; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; @@ -8,6 +9,7 @@ import com.squidex.api.resources.usermanagement.requests.UserManagementGetUsersRequest; import com.squidex.api.types.UserDto; import com.squidex.api.types.UsersDto; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import okhttp3.Headers; @@ -54,8 +56,10 @@ public UsersDto getUsers(UserManagementGetUsersRequest request, RequestOptions r if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UsersDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -93,8 +97,10 @@ public UserDto postUser(CreateUserDto request, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UserDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -120,8 +126,10 @@ public UserDto getUser(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UserDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -162,8 +170,10 @@ public UserDto putUser(String id, UpdateUserDto request, RequestOptions requestO if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UserDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -188,8 +198,10 @@ public void deleteUser(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return; } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -216,8 +228,10 @@ public UserDto lockUser(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UserDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -244,8 +258,10 @@ public UserDto unlockUser(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UserDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/main/java/com/squidex/api/resources/users/UsersClient.java b/src/main/java/com/squidex/api/resources/users/UsersClient.java index 5b35fa5..659acd4 100644 --- a/src/main/java/com/squidex/api/resources/users/UsersClient.java +++ b/src/main/java/com/squidex/api/resources/users/UsersClient.java @@ -1,12 +1,14 @@ package com.squidex.api.resources.users; import com.fasterxml.jackson.core.type.TypeReference; +import com.squidex.api.core.ApiError; import com.squidex.api.core.ClientOptions; import com.squidex.api.core.ObjectMappers; import com.squidex.api.core.RequestOptions; import com.squidex.api.resources.users.requests.UsersGetUsersRequest; import com.squidex.api.types.ResourcesDto; import com.squidex.api.types.UserDto; +import java.io.IOException; import java.io.InputStream; import java.util.List; import okhttp3.Headers; @@ -42,8 +44,10 @@ public ResourcesDto getUserResources(RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), ResourcesDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -73,8 +77,10 @@ public List getUsers(UsersGetUsersRequest request, RequestOptions reque return ObjectMappers.JSON_MAPPER.readValue( _response.body().string(), new TypeReference>() {}); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -100,8 +106,10 @@ public UserDto getUser(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), UserDto.class); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } @@ -128,8 +136,10 @@ public InputStream getUserPicture(String id, RequestOptions requestOptions) { if (_response.isSuccessful()) { return _response.body().byteStream(); } - throw new RuntimeException(); - } catch (Exception e) { + throw new ApiError( + _response.code(), + ObjectMappers.JSON_MAPPER.readValue(_response.body().string(), Object.class)); + } catch (IOException e) { throw new RuntimeException(e); } } diff --git a/src/test/java/com/squidex/api/TestClient.java b/src/test/java/com/squidex/api/TestClient.java new file mode 100644 index 0000000..5e2fe67 --- /dev/null +++ b/src/test/java/com/squidex/api/TestClient.java @@ -0,0 +1,8 @@ +package com.squidex.api; + +public final class TestClient { + public void test() { + // Add tests here and mark this file in .fernignore + assert true; + } +}