diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fbd9082d7..4a2f7e609 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.5.0" + ".": "1.5.1" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index d44c6fa94..9450f45c5 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 116 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/orb%2Forb-612316c13276a207f56e2e2c7bbc68f4bb73de85e3661595a23f23d9ccc80276.yml openapi_spec_hash: 6e125f05e40521ec485edf6e15beec2e -config_hash: 3c3524be9607afb24d2139ce26ce5389 +config_hash: 8c9a47f104c777e2a1e8f3fad15c093b diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a90db914..c220f91a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 1.5.1 (2025-07-17) + +Full Changelog: [v1.5.0...v1.5.1](https://github.com/orbcorp/orb-java/compare/v1.5.0...v1.5.1) + +### Bug Fixes + +* **client:** ensure error handling always occurs ([833326e](https://github.com/orbcorp/orb-java/commit/833326e6f35b4b8575002fc31f89f8292343a9e0)) + ## 1.5.0 (2025-07-16) Full Changelog: [v1.4.0...v1.5.0](https://github.com/orbcorp/orb-java/compare/v1.4.0...v1.5.0) diff --git a/README.md b/README.md index 6597099bd..cc85f41f8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/1.5.0) +[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/1.5.1) @@ -19,7 +19,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.witho ### Gradle ```kotlin -implementation("com.withorb.api:orb-java:1.5.0") +implementation("com.withorb.api:orb-java:1.5.1") ``` ### Maven @@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-java:1.5.0") com.withorb.api orb-java - 1.5.0 + 1.5.1 ``` diff --git a/build.gradle.kts b/build.gradle.kts index d893df117..103754787 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ allprojects { group = "com.withorb.api" - version = "1.5.0" // x-release-please-version + version = "1.5.1" // x-release-please-version } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/handlers/ErrorHandler.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/handlers/ErrorHandler.kt index 70ed82f39..335878efc 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/core/handlers/ErrorHandler.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/handlers/ErrorHandler.kt @@ -19,7 +19,7 @@ import com.withorb.api.errors.UnexpectedStatusCodeException import com.withorb.api.errors.UnprocessableEntityException @JvmSynthetic -internal fun errorHandler(jsonMapper: JsonMapper): Handler { +internal fun errorBodyHandler(jsonMapper: JsonMapper): Handler { val handler = jsonHandler(jsonMapper) return object : Handler { @@ -33,52 +33,52 @@ internal fun errorHandler(jsonMapper: JsonMapper): Handler { } @JvmSynthetic -internal fun Handler.withErrorHandler(errorHandler: Handler): Handler = - object : Handler { - override fun handle(response: HttpResponse): T = +internal fun errorHandler(errorBodyHandler: Handler): Handler = + object : Handler { + override fun handle(response: HttpResponse): HttpResponse = when (val statusCode = response.statusCode()) { - in 200..299 -> this@withErrorHandler.handle(response) + in 200..299 -> response 400 -> throw BadRequestException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 401 -> throw UnauthorizedException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 403 -> throw PermissionDeniedException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 404 -> throw NotFoundException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 422 -> throw UnprocessableEntityException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() 429 -> throw RateLimitException.builder() .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() in 500..599 -> throw InternalServerException.builder() .statusCode(statusCode) .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() else -> throw UnexpectedStatusCodeException.builder() .statusCode(statusCode) .headers(response.headers()) - .body(errorHandler.handle(response)) + .body(errorBodyHandler.handle(response)) .build() } } diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt index 158399fbc..37fde9f01 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/AlertServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -102,7 +102,8 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AlertServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -111,8 +112,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie clientOptions.toBuilder().apply(modifier::accept).build() ) - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: AlertRetrieveParams, @@ -132,7 +132,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -144,8 +144,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: AlertUpdateParams, @@ -166,7 +165,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -180,7 +179,6 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: AlertListParams, @@ -197,7 +195,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -218,7 +216,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } private val createForCustomerHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createForCustomer( params: AlertCreateForCustomerParams, @@ -239,7 +237,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createForCustomerHandler.handle(it) } .also { @@ -252,7 +250,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } private val createForExternalCustomerHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createForExternalCustomer( params: AlertCreateForExternalCustomerParams, @@ -273,7 +271,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createForExternalCustomerHandler.handle(it) } .also { @@ -286,7 +284,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } private val createForSubscriptionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createForSubscription( params: AlertCreateForSubscriptionParams, @@ -307,7 +305,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createForSubscriptionHandler.handle(it) } .also { @@ -319,8 +317,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val disableHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val disableHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun disable( params: AlertDisableParams, @@ -341,7 +338,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { disableHandler.handle(it) } .also { @@ -353,8 +350,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val enableHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val enableHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun enable( params: AlertEnableParams, @@ -375,7 +371,7 @@ class AlertServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { enableHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsyncImpl.kt index 5cb71fb13..9af837003 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/BetaServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -69,7 +69,8 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BetaServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalPlanId: ExternalPlanIdServiceAsync.WithRawResponse by lazy { ExternalPlanIdServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -85,7 +86,7 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun externalPlanId(): ExternalPlanIdServiceAsync.WithRawResponse = externalPlanId private val createPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createPlanVersion( params: BetaCreatePlanVersionParams, @@ -106,7 +107,7 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createPlanVersionHandler.handle(it) } .also { @@ -119,7 +120,7 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien } private val fetchPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchPlanVersion( params: BetaFetchPlanVersionParams, @@ -144,7 +145,7 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchPlanVersionHandler.handle(it) } .also { @@ -157,7 +158,7 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien } private val setDefaultPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun setDefaultPlanVersion( params: BetaSetDefaultPlanVersionParams, @@ -178,7 +179,7 @@ class BetaServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { setDefaultPlanVersionHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt index 77fe37124..d25042cbd 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CouponServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -78,7 +78,8 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CouponServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val subscriptions: SubscriptionServiceAsync.WithRawResponse by lazy { SubscriptionServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -93,8 +94,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun subscriptions(): SubscriptionServiceAsync.WithRawResponse = subscriptions - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: CouponCreateParams, @@ -112,7 +112,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -126,7 +126,6 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CouponListParams, @@ -143,7 +142,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -163,8 +162,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val archiveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val archiveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun archive( params: CouponArchiveParams, @@ -185,7 +183,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { archiveHandler.handle(it) } .also { @@ -197,8 +195,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: CouponFetchParams, @@ -218,7 +215,7 @@ class CouponServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt index c803b1834..ab1a9466a 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CreditNoteServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -62,7 +62,8 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CreditNoteServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -72,7 +73,7 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: CreditNoteCreateParams, @@ -90,7 +91,7 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -104,7 +105,6 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CreditNoteListParams, @@ -121,7 +121,7 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -142,7 +142,7 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: CreditNoteFetchParams, @@ -162,7 +162,7 @@ class CreditNoteServiceAsyncImpl internal constructor(private val clientOptions: return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt index 20edac10c..e4c490df1 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/CustomerServiceAsyncImpl.kt @@ -3,13 +3,12 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired import com.withorb.api.core.handlers.emptyHandler +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest import com.withorb.api.core.http.HttpResponse @@ -135,7 +134,8 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CustomerServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val costs: CostServiceAsync.WithRawResponse by lazy { CostServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -164,7 +164,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C balanceTransactions private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: CustomerCreateParams, @@ -182,7 +182,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -195,7 +195,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: CustomerUpdateParams, @@ -216,7 +216,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -230,7 +230,6 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerListParams, @@ -247,7 +246,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -267,7 +266,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } } - private val deleteHandler: Handler = emptyHandler().withErrorHandler(errorHandler) + private val deleteHandler: Handler = emptyHandler() override fun delete( params: CustomerDeleteParams, @@ -288,12 +287,14 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { response.use { deleteHandler.handle(it) } } + errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } } } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: CustomerFetchParams, @@ -313,7 +314,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -326,7 +327,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } private val fetchByExternalIdHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchByExternalId( params: CustomerFetchByExternalIdParams, @@ -346,7 +347,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchByExternalIdHandler.handle(it) } .also { @@ -358,8 +359,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } } - private val syncPaymentMethodsFromGatewayHandler: Handler = - emptyHandler().withErrorHandler(errorHandler) + private val syncPaymentMethodsFromGatewayHandler: Handler = emptyHandler() override fun syncPaymentMethodsFromGateway( params: CustomerSyncPaymentMethodsFromGatewayParams, @@ -384,14 +384,14 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response.use { syncPaymentMethodsFromGatewayHandler.handle(it) } } } } private val syncPaymentMethodsFromGatewayByExternalCustomerIdHandler: Handler = - emptyHandler().withErrorHandler(errorHandler) + emptyHandler() override fun syncPaymentMethodsFromGatewayByExternalCustomerId( params: CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams, @@ -417,7 +417,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response.use { syncPaymentMethodsFromGatewayByExternalCustomerIdHandler.handle(it) } @@ -426,7 +426,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C } private val updateByExternalIdHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun updateByExternalId( params: CustomerUpdateByExternalIdParams, @@ -447,7 +447,7 @@ class CustomerServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt index 80c26820a..3566c6472 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/DimensionalPriceGroupServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -77,7 +77,8 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : DimensionalPriceGroupServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalDimensionalPriceGroupId: ExternalDimensionalPriceGroupIdServiceAsync.WithRawResponse by lazy { @@ -97,7 +98,6 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: DimensionalPriceGroupCreateParams, @@ -115,7 +115,7 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -129,7 +129,6 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun retrieve( params: DimensionalPriceGroupRetrieveParams, @@ -149,7 +148,7 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -163,7 +162,6 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: DimensionalPriceGroupListParams, @@ -180,7 +178,7 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsyncImpl.kt index 397718b57..782512a84 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/EventServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -83,7 +83,8 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EventServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val backfills: BackfillServiceAsync.WithRawResponse by lazy { BackfillServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -106,7 +107,6 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun update( params: EventUpdateParams, @@ -127,7 +127,7 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -141,7 +141,6 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie private val deprecateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun deprecate( params: EventDeprecateParams, @@ -162,7 +161,7 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { deprecateHandler.handle(it) } .also { @@ -176,7 +175,6 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie private val ingestHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun ingest( params: EventIngestParams, @@ -194,7 +192,7 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { ingestHandler.handle(it) } .also { @@ -208,7 +206,6 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie private val searchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun search( params: EventSearchParams, @@ -226,7 +223,7 @@ class EventServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { searchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncImpl.kt index 5993e2551..58ac0b84d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceLineItemServiceAsyncImpl.kt @@ -3,13 +3,13 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -44,7 +44,8 @@ internal constructor(private val clientOptions: ClientOptions) : InvoiceLineItem class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : InvoiceLineItemServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -55,7 +56,6 @@ internal constructor(private val clientOptions: ClientOptions) : InvoiceLineItem private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: InvoiceLineItemCreateParams, @@ -73,7 +73,7 @@ internal constructor(private val clientOptions: ClientOptions) : InvoiceLineItem return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt index 3fceafccb..b3504b524 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/InvoiceServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -111,7 +111,8 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : InvoiceServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -120,8 +121,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl clientOptions.toBuilder().apply(modifier::accept).build() ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: InvoiceCreateParams, @@ -139,7 +139,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -151,8 +151,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: InvoiceUpdateParams, @@ -173,7 +172,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -187,7 +186,6 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: InvoiceListParams, @@ -204,7 +202,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -224,8 +222,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: InvoiceFetchParams, @@ -245,7 +242,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -259,7 +256,6 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl private val fetchUpcomingHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchUpcoming( params: InvoiceFetchUpcomingParams, @@ -276,7 +272,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchUpcomingHandler.handle(it) } .also { @@ -288,8 +284,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val issueHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val issueHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun issue( params: InvoiceIssueParams, @@ -310,7 +305,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { issueHandler.handle(it) } .also { @@ -323,7 +318,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } private val markPaidHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun markPaid( params: InvoiceMarkPaidParams, @@ -344,7 +339,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { markPaidHandler.handle(it) } .also { @@ -356,8 +351,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } } - private val payHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val payHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun pay( params: InvoicePayParams, @@ -378,7 +372,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { payHandler.handle(it) } .also { @@ -391,7 +385,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl } private val voidInvoiceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun voidInvoice( params: InvoiceVoidInvoiceParams, @@ -412,7 +406,7 @@ class InvoiceServiceAsyncImpl internal constructor(private val clientOptions: Cl return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { voidInvoiceHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt index a8c776b0c..d17818542 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/ItemServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -78,7 +78,8 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ItemServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -87,8 +88,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien clientOptions.toBuilder().apply(modifier::accept).build() ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: ItemCreateParams, @@ -106,7 +106,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -118,8 +118,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: ItemUpdateParams, @@ -140,7 +139,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -154,7 +153,6 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ItemListParams, @@ -171,7 +169,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -191,8 +189,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val archiveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val archiveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun archive( params: ItemArchiveParams, @@ -213,7 +210,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { archiveHandler.handle(it) } .also { @@ -225,8 +222,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: ItemFetchParams, @@ -246,7 +242,7 @@ class ItemServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt index ba202affb..756da69a9 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/MetricServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -70,7 +70,8 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MetricServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -80,7 +81,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: MetricCreateParams, @@ -98,7 +99,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -111,7 +112,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: MetricUpdateParams, @@ -132,7 +133,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -146,7 +147,6 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: MetricListParams, @@ -163,7 +163,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -184,7 +184,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: MetricFetchParams, @@ -204,7 +204,7 @@ class MetricServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt index f57206eef..4e5cb6212 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PlanServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -78,7 +78,8 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PlanServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalPlanId: ExternalPlanIdServiceAsync.WithRawResponse by lazy { ExternalPlanIdServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -93,8 +94,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien override fun externalPlanId(): ExternalPlanIdServiceAsync.WithRawResponse = externalPlanId - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: PlanCreateParams, @@ -112,7 +112,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -124,8 +124,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PlanUpdateParams, @@ -146,7 +145,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -160,7 +159,6 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: PlanListParams, @@ -177,7 +175,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -197,8 +195,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PlanFetchParams, @@ -218,7 +215,7 @@ class PlanServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt index b0b0530da..e7573d2e5 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/PriceServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -105,7 +105,8 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PriceServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalPriceId: ExternalPriceIdServiceAsync.WithRawResponse by lazy { ExternalPriceIdServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -121,8 +122,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie override fun externalPriceId(): ExternalPriceIdServiceAsync.WithRawResponse = externalPriceId - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: PriceCreateParams, @@ -140,7 +140,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -152,8 +152,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PriceUpdateParams, @@ -174,7 +173,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -188,7 +187,6 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: PriceListParams, @@ -205,7 +203,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -227,7 +225,6 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie private val evaluateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun evaluate( params: PriceEvaluateParams, @@ -248,7 +245,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { evaluateHandler.handle(it) } .also { @@ -262,7 +259,6 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie private val evaluateMultipleHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun evaluateMultiple( params: PriceEvaluateMultipleParams, @@ -280,7 +276,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { evaluateMultipleHandler.handle(it) } .also { @@ -294,7 +290,6 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie private val evaluatePreviewEventsHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun evaluatePreviewEvents( params: PriceEvaluatePreviewEventsParams, @@ -312,7 +307,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { evaluatePreviewEventsHandler.handle(it) } .also { @@ -324,8 +319,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PriceFetchParams, @@ -345,7 +339,7 @@ class PriceServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncImpl.kt index 41b345768..d58f5a87e 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionChangeServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -66,7 +66,8 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionChangeServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -77,7 +78,6 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun retrieve( params: SubscriptionChangeRetrieveParams, @@ -97,7 +97,7 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -111,7 +111,6 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha private val applyHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun apply( params: SubscriptionChangeApplyParams, @@ -132,7 +131,7 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { applyHandler.handle(it) } .also { @@ -146,7 +145,6 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha private val cancelHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun cancel( params: SubscriptionChangeCancelParams, @@ -167,7 +165,7 @@ internal constructor(private val clientOptions: ClientOptions) : SubscriptionCha return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { cancelHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt index 0ea0f6af7..151dc1fbe 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/SubscriptionServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -183,7 +183,8 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -194,7 +195,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: SubscriptionCreateParams, @@ -212,7 +212,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -225,7 +225,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: SubscriptionUpdateParams, @@ -246,7 +246,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -259,7 +259,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: SubscriptionListParams, @@ -276,7 +276,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -298,7 +298,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val cancelHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun cancel( params: SubscriptionCancelParams, @@ -319,7 +318,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { cancelHandler.handle(it) } .also { @@ -332,7 +331,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: SubscriptionFetchParams, @@ -352,7 +351,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -366,7 +365,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val fetchCostsHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchCosts( params: SubscriptionFetchCostsParams, @@ -386,7 +384,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchCostsHandler.handle(it) } .also { @@ -400,7 +398,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val fetchScheduleHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchSchedule( params: SubscriptionFetchScheduleParams, @@ -420,7 +417,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchScheduleHandler.handle(it) } .also { @@ -441,7 +438,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption } private val fetchUsageHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchUsage( params: SubscriptionFetchUsageParams, @@ -461,7 +458,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchUsageHandler.handle(it) } .also { @@ -475,7 +472,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val priceIntervalsHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun priceIntervals( params: SubscriptionPriceIntervalsParams, @@ -496,7 +492,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { priceIntervalsHandler.handle(it) } .also { @@ -510,7 +506,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val redeemCouponHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun redeemCoupon( params: SubscriptionRedeemCouponParams, @@ -531,7 +526,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { redeemCouponHandler.handle(it) } .also { @@ -545,7 +540,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val schedulePlanChangeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun schedulePlanChange( params: SubscriptionSchedulePlanChangeParams, @@ -566,7 +560,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { schedulePlanChangeHandler.handle(it) } .also { @@ -580,7 +574,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val triggerPhaseHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun triggerPhase( params: SubscriptionTriggerPhaseParams, @@ -601,7 +594,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { triggerPhaseHandler.handle(it) } .also { @@ -615,7 +608,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val unscheduleCancellationHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun unscheduleCancellation( params: SubscriptionUnscheduleCancellationParams, @@ -640,7 +632,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { unscheduleCancellationHandler.handle(it) } .also { @@ -654,7 +646,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val unscheduleFixedFeeQuantityUpdatesHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun unscheduleFixedFeeQuantityUpdates( params: SubscriptionUnscheduleFixedFeeQuantityUpdatesParams, @@ -679,7 +670,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { unscheduleFixedFeeQuantityUpdatesHandler.handle(it) } .also { @@ -693,7 +684,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val unschedulePendingPlanChangesHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun unschedulePendingPlanChanges( params: SubscriptionUnschedulePendingPlanChangesParams, @@ -718,7 +708,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { unschedulePendingPlanChangesHandler.handle(it) } .also { @@ -732,7 +722,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val updateFixedFeeQuantityHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun updateFixedFeeQuantity( params: SubscriptionUpdateFixedFeeQuantityParams, @@ -757,7 +746,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateFixedFeeQuantityHandler.handle(it) } .also { @@ -771,7 +760,6 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption private val updateTrialHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun updateTrial( params: SubscriptionUpdateTrialParams, @@ -792,7 +780,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateTrialHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/TopLevelServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/TopLevelServiceAsyncImpl.kt index f2d8276c5..ba656dedc 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/TopLevelServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/TopLevelServiceAsyncImpl.kt @@ -3,13 +3,13 @@ package com.withorb.api.services.async import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -41,7 +41,8 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -52,7 +53,6 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C private val pingHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun ping( params: TopLevelPingParams, @@ -69,7 +69,7 @@ class TopLevelServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { pingHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncImpl.kt index 7be5dc93b..3d41085ce 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/beta/ExternalPlanIdServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.beta import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -63,7 +63,8 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -73,7 +74,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS ) private val createPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createPlanVersion( params: BetaExternalPlanIdCreatePlanVersionParams, @@ -94,7 +95,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createPlanVersionHandler.handle(it) } .also { @@ -107,7 +108,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS } private val fetchPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchPlanVersion( params: BetaExternalPlanIdFetchPlanVersionParams, @@ -133,7 +134,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchPlanVersionHandler.handle(it) } .also { @@ -146,7 +147,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS } private val setDefaultPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun setDefaultPlanVersion( params: BetaExternalPlanIdSetDefaultPlanVersionParams, @@ -172,7 +173,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { setDefaultPlanVersionHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt index 7edc9cb67..1695a6e13 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/coupons/SubscriptionServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.coupons import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -44,7 +44,8 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -54,7 +55,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption ) private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: CouponSubscriptionListParams, @@ -74,7 +75,7 @@ class SubscriptionServiceAsyncImpl internal constructor(private val clientOption return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt index d4337539d..a9c5ec052 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/BalanceTransactionServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.customers import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -58,7 +58,8 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BalanceTransactionServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -69,7 +70,6 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: CustomerBalanceTransactionCreateParams, @@ -90,7 +90,7 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -104,7 +104,6 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerBalanceTransactionListParams, @@ -124,7 +123,7 @@ internal constructor(private val clientOptions: ClientOptions) : BalanceTransact return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsyncImpl.kt index 7437de1f1..3c1970d8c 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CostServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.customers import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -52,7 +52,8 @@ class CostServiceAsyncImpl internal constructor(private val clientOptions: Clien class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CostServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -63,7 +64,6 @@ class CostServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCostListParams, @@ -83,7 +83,7 @@ class CostServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -97,7 +97,6 @@ class CostServiceAsyncImpl internal constructor(private val clientOptions: Clien private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCostListByExternalIdParams, @@ -122,7 +121,7 @@ class CostServiceAsyncImpl internal constructor(private val clientOptions: Clien return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt index fbfc2ee29..41f0ffa95 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/CreditServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.customers import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -66,7 +66,8 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CreditServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val ledger: LedgerServiceAsync.WithRawResponse by lazy { LedgerServiceAsyncImpl.WithRawResponseImpl(clientOptions) @@ -89,7 +90,6 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCreditListParams, @@ -109,7 +109,7 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -131,7 +131,6 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCreditListByExternalIdParams, @@ -156,7 +155,7 @@ class CreditServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt index 63b572865..671f24628 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/LedgerServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.customers.credits import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -73,7 +73,8 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : LedgerServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -84,7 +85,6 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCreditLedgerListParams, @@ -104,7 +104,7 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -126,7 +126,6 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli private val createEntryHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun createEntry( params: CustomerCreditLedgerCreateEntryParams, @@ -147,7 +146,7 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createEntryHandler.handle(it) } .also { @@ -162,9 +161,8 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli private val createEntryByExternalIdHandler: Handler = jsonHandler( - clientOptions.jsonMapper - ) - .withErrorHandler(errorHandler) + clientOptions.jsonMapper + ) override fun createEntryByExternalId( params: CustomerCreditLedgerCreateEntryByExternalIdParams, @@ -191,7 +189,7 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createEntryByExternalIdHandler.handle(it) } .also { @@ -206,7 +204,6 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCreditLedgerListByExternalIdParams, @@ -232,7 +229,7 @@ class LedgerServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt index c59f5d1b2..5066212e6 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/customers/credits/TopUpServiceAsyncImpl.kt @@ -3,13 +3,12 @@ package com.withorb.api.services.async.customers.credits import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired import com.withorb.api.core.handlers.emptyHandler +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest import com.withorb.api.core.http.HttpResponse @@ -91,7 +90,8 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopUpServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -102,7 +102,6 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: CustomerCreditTopUpCreateParams, @@ -123,7 +122,7 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -137,7 +136,6 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCreditTopUpListParams, @@ -157,7 +155,7 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -177,7 +175,7 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val deleteHandler: Handler = emptyHandler().withErrorHandler(errorHandler) + private val deleteHandler: Handler = emptyHandler() override fun delete( params: CustomerCreditTopUpDeleteParams, @@ -204,14 +202,15 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { response.use { deleteHandler.handle(it) } } + errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } } } private val createByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun createByExternalId( params: CustomerCreditTopUpCreateByExternalIdParams, @@ -238,7 +237,7 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createByExternalIdHandler.handle(it) } .also { @@ -250,8 +249,7 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie } } - private val deleteByExternalIdHandler: Handler = - emptyHandler().withErrorHandler(errorHandler) + private val deleteByExternalIdHandler: Handler = emptyHandler() override fun deleteByExternalId( params: CustomerCreditTopUpDeleteByExternalIdParams, @@ -279,14 +277,15 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { response.use { deleteByExternalIdHandler.handle(it) } } + errorHandler.handle(response).parseable { + response.use { deleteByExternalIdHandler.handle(it) } + } } } private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCreditTopUpListByExternalIdParams, @@ -312,7 +311,7 @@ class TopUpServiceAsyncImpl internal constructor(private val clientOptions: Clie return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceAsyncImpl.kt index 37e6f5427..c9a79447c 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.dimensionalPriceGroups import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -51,7 +51,8 @@ internal constructor(private val clientOptions: ClientOptions) : class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalDimensionalPriceGroupIdServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -62,7 +63,6 @@ internal constructor(private val clientOptions: ClientOptions) : private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun retrieve( params: DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams, @@ -89,7 +89,7 @@ internal constructor(private val clientOptions: ClientOptions) : return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt index b57a8261d..6ca450b93 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/BackfillServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.events import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -81,7 +81,8 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BackfillServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -92,7 +93,6 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: EventBackfillCreateParams, @@ -110,7 +110,7 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -124,7 +124,6 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: EventBackfillListParams, @@ -141,7 +140,7 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -163,7 +162,6 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C private val closeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun close( params: EventBackfillCloseParams, @@ -184,7 +182,7 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { closeHandler.handle(it) } .also { @@ -198,7 +196,6 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: EventBackfillFetchParams, @@ -218,7 +215,7 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -232,7 +229,6 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C private val revertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun revert( params: EventBackfillRevertParams, @@ -253,7 +249,7 @@ class BackfillServiceAsyncImpl internal constructor(private val clientOptions: C return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { revertHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/VolumeServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/VolumeServiceAsyncImpl.kt index 41c564ffa..bdb94fcc3 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/VolumeServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/events/VolumeServiceAsyncImpl.kt @@ -3,13 +3,13 @@ package com.withorb.api.services.async.events import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -41,7 +41,8 @@ class VolumeServiceAsyncImpl internal constructor(private val clientOptions: Cli class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : VolumeServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -51,7 +52,7 @@ class VolumeServiceAsyncImpl internal constructor(private val clientOptions: Cli ) private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: EventVolumeListParams, @@ -68,7 +69,7 @@ class VolumeServiceAsyncImpl internal constructor(private val clientOptions: Cli return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsyncImpl.kt index 50d7525a6..f793de045 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/plans/ExternalPlanIdServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.plans import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -54,7 +54,8 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -63,8 +64,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS clientOptions.toBuilder().apply(modifier::accept).build() ) - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PlanExternalPlanIdUpdateParams, @@ -85,7 +85,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -97,8 +97,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PlanExternalPlanIdFetchParams, @@ -118,7 +117,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdS return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/prices/ExternalPriceIdServiceAsyncImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/prices/ExternalPriceIdServiceAsyncImpl.kt index 6384a65a0..00580b869 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/async/prices/ExternalPriceIdServiceAsyncImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/async/prices/ExternalPriceIdServiceAsyncImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.async.prices import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -54,7 +54,8 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPriceId class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalPriceIdServiceAsync.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -63,8 +64,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPriceId clientOptions.toBuilder().apply(modifier::accept).build() ) - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PriceExternalPriceIdUpdateParams, @@ -85,7 +85,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPriceId return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -97,8 +97,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPriceId } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PriceExternalPriceIdFetchParams, @@ -118,7 +117,7 @@ internal constructor(private val clientOptions: ClientOptions) : ExternalPriceId return request .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> - response.parseable { + errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt index 5911e5a48..daa8d5ff5 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/AlertServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -86,7 +86,8 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : AlertService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -95,8 +96,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt clientOptions.toBuilder().apply(modifier::accept).build() ) - private val retrieveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun retrieve( params: AlertRetrieveParams, @@ -114,7 +114,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -125,8 +125,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: AlertUpdateParams, @@ -145,7 +144,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -158,7 +157,6 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: AlertListParams, @@ -173,7 +171,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -192,7 +190,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } private val createForCustomerHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createForCustomer( params: AlertCreateForCustomerParams, @@ -211,7 +209,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createForCustomerHandler.handle(it) } .also { @@ -223,7 +221,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } private val createForExternalCustomerHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createForExternalCustomer( params: AlertCreateForExternalCustomerParams, @@ -242,7 +240,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createForExternalCustomerHandler.handle(it) } .also { @@ -254,7 +252,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } private val createForSubscriptionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createForSubscription( params: AlertCreateForSubscriptionParams, @@ -273,7 +271,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createForSubscriptionHandler.handle(it) } .also { @@ -284,8 +282,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val disableHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val disableHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun disable( params: AlertDisableParams, @@ -304,7 +301,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { disableHandler.handle(it) } .also { @@ -315,8 +312,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val enableHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val enableHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun enable( params: AlertEnableParams, @@ -335,7 +331,7 @@ class AlertServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { enableHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/BetaServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/BetaServiceImpl.kt index d59eab2a5..c9916655e 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/BetaServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/BetaServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -67,7 +67,8 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BetaService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalPlanId: ExternalPlanIdService.WithRawResponse by lazy { ExternalPlanIdServiceImpl.WithRawResponseImpl(clientOptions) @@ -83,7 +84,7 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti override fun externalPlanId(): ExternalPlanIdService.WithRawResponse = externalPlanId private val createPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createPlanVersion( params: BetaCreatePlanVersionParams, @@ -102,7 +103,7 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createPlanVersionHandler.handle(it) } .also { @@ -114,7 +115,7 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti } private val fetchPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchPlanVersion( params: BetaFetchPlanVersionParams, @@ -137,7 +138,7 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchPlanVersionHandler.handle(it) } .also { @@ -149,7 +150,7 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti } private val setDefaultPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun setDefaultPlanVersion( params: BetaSetDefaultPlanVersionParams, @@ -168,7 +169,7 @@ class BetaServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { setDefaultPlanVersionHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt index 002a99a79..479d31180 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CouponServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -65,7 +65,8 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CouponService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val subscriptions: SubscriptionService.WithRawResponse by lazy { SubscriptionServiceImpl.WithRawResponseImpl(clientOptions) @@ -80,8 +81,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp override fun subscriptions(): SubscriptionService.WithRawResponse = subscriptions - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: CouponCreateParams, @@ -97,7 +97,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -110,7 +110,6 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CouponListParams, @@ -125,7 +124,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -143,8 +142,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val archiveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val archiveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun archive( params: CouponArchiveParams, @@ -163,7 +161,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { archiveHandler.handle(it) } .also { @@ -174,8 +172,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: CouponFetchParams, @@ -193,7 +190,7 @@ class CouponServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt index cf6e0f8f1..14d2f531b 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CreditNoteServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -58,7 +58,8 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CreditNoteService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -68,7 +69,7 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: CreditNoteCreateParams, @@ -84,7 +85,7 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -97,7 +98,6 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CreditNoteListParams, @@ -112,7 +112,7 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -131,7 +131,7 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: CreditNoteFetchParams, @@ -149,7 +149,7 @@ class CreditNoteServiceImpl internal constructor(private val clientOptions: Clie .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt index b36c08c85..14a609ddc 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/CustomerServiceImpl.kt @@ -3,13 +3,12 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired import com.withorb.api.core.handlers.emptyHandler +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest import com.withorb.api.core.http.HttpResponse @@ -123,7 +122,8 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CustomerService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val costs: CostService.WithRawResponse by lazy { CostServiceImpl.WithRawResponseImpl(clientOptions) @@ -152,7 +152,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client balanceTransactions private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: CustomerCreateParams, @@ -168,7 +168,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -180,7 +180,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: CustomerUpdateParams, @@ -199,7 +199,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -212,7 +212,6 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerListParams, @@ -227,7 +226,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -245,7 +244,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client } } - private val deleteHandler: Handler = emptyHandler().withErrorHandler(errorHandler) + private val deleteHandler: Handler = emptyHandler() override fun delete( params: CustomerDeleteParams, @@ -264,11 +263,13 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { response.use { deleteHandler.handle(it) } } + return errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: CustomerFetchParams, @@ -286,7 +287,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -298,7 +299,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client } private val fetchByExternalIdHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchByExternalId( params: CustomerFetchByExternalIdParams, @@ -316,7 +317,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchByExternalIdHandler.handle(it) } .also { @@ -327,8 +328,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client } } - private val syncPaymentMethodsFromGatewayHandler: Handler = - emptyHandler().withErrorHandler(errorHandler) + private val syncPaymentMethodsFromGatewayHandler: Handler = emptyHandler() override fun syncPaymentMethodsFromGateway( params: CustomerSyncPaymentMethodsFromGatewayParams, @@ -351,13 +351,13 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response.use { syncPaymentMethodsFromGatewayHandler.handle(it) } } } private val syncPaymentMethodsFromGatewayByExternalCustomerIdHandler: Handler = - emptyHandler().withErrorHandler(errorHandler) + emptyHandler() override fun syncPaymentMethodsFromGatewayByExternalCustomerId( params: CustomerSyncPaymentMethodsFromGatewayByExternalCustomerIdParams, @@ -381,13 +381,13 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response.use { syncPaymentMethodsFromGatewayByExternalCustomerIdHandler.handle(it) } } } private val updateByExternalIdHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun updateByExternalId( params: CustomerUpdateByExternalIdParams, @@ -406,7 +406,7 @@ class CustomerServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt index 4646747d8..c682a7f06 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/DimensionalPriceGroupServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -72,7 +72,8 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : DimensionalPriceGroupService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalDimensionalPriceGroupId: ExternalDimensionalPriceGroupIdService.WithRawResponse by lazy { @@ -91,7 +92,6 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: DimensionalPriceGroupCreateParams, @@ -107,7 +107,7 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -120,7 +120,6 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun retrieve( params: DimensionalPriceGroupRetrieveParams, @@ -138,7 +137,7 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -151,7 +150,6 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: DimensionalPriceGroupListParams, @@ -166,7 +164,7 @@ internal constructor(private val clientOptions: ClientOptions) : DimensionalPric .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/EventServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/EventServiceImpl.kt index 9ef46bde5..96d616787 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/EventServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/EventServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -82,7 +82,8 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : EventService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val backfills: BackfillService.WithRawResponse by lazy { BackfillServiceImpl.WithRawResponseImpl(clientOptions) @@ -105,7 +106,6 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun update( params: EventUpdateParams, @@ -124,7 +124,7 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -137,7 +137,6 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt private val deprecateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun deprecate( params: EventDeprecateParams, @@ -156,7 +155,7 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { deprecateHandler.handle(it) } .also { @@ -169,7 +168,6 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt private val ingestHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun ingest( params: EventIngestParams, @@ -185,7 +183,7 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { ingestHandler.handle(it) } .also { @@ -198,7 +196,6 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt private val searchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun search( params: EventSearchParams, @@ -214,7 +211,7 @@ class EventServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { searchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceImpl.kt index 00876f358..b6202b351 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceLineItemServiceImpl.kt @@ -3,13 +3,13 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -41,7 +41,8 @@ class InvoiceLineItemServiceImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : InvoiceLineItemService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -52,7 +53,6 @@ class InvoiceLineItemServiceImpl internal constructor(private val clientOptions: private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: InvoiceLineItemCreateParams, @@ -68,7 +68,7 @@ class InvoiceLineItemServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt index 1a760a819..bded90fac 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/InvoiceServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -89,7 +89,8 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : InvoiceService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -98,8 +99,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO clientOptions.toBuilder().apply(modifier::accept).build() ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: InvoiceCreateParams, @@ -115,7 +115,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -126,8 +126,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: InvoiceUpdateParams, @@ -146,7 +145,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -159,7 +158,6 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: InvoiceListParams, @@ -174,7 +172,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -192,8 +190,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: InvoiceFetchParams, @@ -211,7 +208,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -224,7 +221,6 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO private val fetchUpcomingHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchUpcoming( params: InvoiceFetchUpcomingParams, @@ -239,7 +235,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchUpcomingHandler.handle(it) } .also { @@ -250,8 +246,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } } - private val issueHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val issueHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun issue( params: InvoiceIssueParams, @@ -270,7 +265,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { issueHandler.handle(it) } .also { @@ -282,7 +277,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } private val markPaidHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun markPaid( params: InvoiceMarkPaidParams, @@ -301,7 +296,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { markPaidHandler.handle(it) } .also { @@ -312,8 +307,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } } - private val payHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val payHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun pay( params: InvoicePayParams, @@ -332,7 +326,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { payHandler.handle(it) } .also { @@ -344,7 +338,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO } private val voidInvoiceHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun voidInvoice( params: InvoiceVoidInvoiceParams, @@ -363,7 +357,7 @@ class InvoiceServiceImpl internal constructor(private val clientOptions: ClientO .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { voidInvoiceHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt index 5adb0fa9a..8378b6a89 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/ItemServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -61,7 +61,8 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ItemService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -70,8 +71,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti clientOptions.toBuilder().apply(modifier::accept).build() ) - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: ItemCreateParams, @@ -87,7 +87,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -98,8 +98,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: ItemUpdateParams, @@ -118,7 +117,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -131,7 +130,6 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: ItemListParams, @@ -146,7 +144,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -164,8 +162,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val archiveHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val archiveHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun archive( params: ItemArchiveParams, @@ -184,7 +181,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { archiveHandler.handle(it) } .also { @@ -195,8 +192,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: ItemFetchParams, @@ -214,7 +210,7 @@ class ItemServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt index 9acb75376..91855682b 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/MetricServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -63,7 +63,8 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MetricService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -73,7 +74,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp ) private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun create( params: MetricCreateParams, @@ -89,7 +90,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -101,7 +102,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: MetricUpdateParams, @@ -120,7 +121,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -133,7 +134,6 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: MetricListParams, @@ -148,7 +148,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -167,7 +167,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: MetricFetchParams, @@ -185,7 +185,7 @@ class MetricServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt index 856d66d40..daa266bec 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PlanServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -64,7 +64,8 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PlanService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalPlanId: ExternalPlanIdService.WithRawResponse by lazy { ExternalPlanIdServiceImpl.WithRawResponseImpl(clientOptions) @@ -79,8 +80,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti override fun externalPlanId(): ExternalPlanIdService.WithRawResponse = externalPlanId - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: PlanCreateParams, @@ -96,7 +96,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -107,8 +107,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PlanUpdateParams, @@ -127,7 +126,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -140,7 +139,6 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: PlanListParams, @@ -155,7 +153,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -173,8 +171,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PlanFetchParams, @@ -192,7 +189,7 @@ class PlanServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt index 53dfa4dd7..f880d0f39 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/PriceServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -92,7 +92,8 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : PriceService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val externalPriceId: ExternalPriceIdService.WithRawResponse by lazy { ExternalPriceIdServiceImpl.WithRawResponseImpl(clientOptions) @@ -107,8 +108,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt override fun externalPriceId(): ExternalPriceIdService.WithRawResponse = externalPriceId - private val createHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun create( params: PriceCreateParams, @@ -124,7 +124,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -135,8 +135,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PriceUpdateParams, @@ -155,7 +154,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -168,7 +167,6 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: PriceListParams, @@ -183,7 +181,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -203,7 +201,6 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt private val evaluateHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun evaluate( params: PriceEvaluateParams, @@ -222,7 +219,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { evaluateHandler.handle(it) } .also { @@ -235,7 +232,6 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt private val evaluateMultipleHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun evaluateMultiple( params: PriceEvaluateMultipleParams, @@ -251,7 +247,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { evaluateMultipleHandler.handle(it) } .also { @@ -264,7 +260,6 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt private val evaluatePreviewEventsHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun evaluatePreviewEvents( params: PriceEvaluatePreviewEventsParams, @@ -280,7 +275,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { evaluatePreviewEventsHandler.handle(it) } .also { @@ -291,8 +286,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PriceFetchParams, @@ -310,7 +304,7 @@ class PriceServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceImpl.kt index 56338b4ec..02f15bedc 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionChangeServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -61,7 +61,8 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionChangeService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -72,7 +73,6 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun retrieve( params: SubscriptionChangeRetrieveParams, @@ -90,7 +90,7 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { @@ -103,7 +103,6 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio private val applyHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun apply( params: SubscriptionChangeApplyParams, @@ -122,7 +121,7 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { applyHandler.handle(it) } .also { @@ -135,7 +134,6 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio private val cancelHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun cancel( params: SubscriptionChangeCancelParams, @@ -154,7 +152,7 @@ class SubscriptionChangeServiceImpl internal constructor(private val clientOptio .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { cancelHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt index d01765c26..7f694362d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/SubscriptionServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -178,7 +178,8 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -189,7 +190,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: SubscriptionCreateParams, @@ -205,7 +205,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -217,7 +217,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun update( params: SubscriptionUpdateParams, @@ -236,7 +236,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -248,7 +248,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: SubscriptionListParams, @@ -263,7 +263,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -283,7 +283,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val cancelHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun cancel( params: SubscriptionCancelParams, @@ -302,7 +301,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { cancelHandler.handle(it) } .also { @@ -314,7 +313,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetch( params: SubscriptionFetchParams, @@ -332,7 +331,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -345,7 +344,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val fetchCostsHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchCosts( params: SubscriptionFetchCostsParams, @@ -363,7 +361,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchCostsHandler.handle(it) } .also { @@ -376,7 +374,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val fetchScheduleHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetchSchedule( params: SubscriptionFetchScheduleParams, @@ -394,7 +391,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchScheduleHandler.handle(it) } .also { @@ -413,7 +410,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl } private val fetchUsageHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchUsage( params: SubscriptionFetchUsageParams, @@ -431,7 +428,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchUsageHandler.handle(it) } .also { @@ -444,7 +441,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val priceIntervalsHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun priceIntervals( params: SubscriptionPriceIntervalsParams, @@ -463,7 +459,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { priceIntervalsHandler.handle(it) } .also { @@ -476,7 +472,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val redeemCouponHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun redeemCoupon( params: SubscriptionRedeemCouponParams, @@ -495,7 +490,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { redeemCouponHandler.handle(it) } .also { @@ -508,7 +503,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val schedulePlanChangeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun schedulePlanChange( params: SubscriptionSchedulePlanChangeParams, @@ -527,7 +521,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { schedulePlanChangeHandler.handle(it) } .also { @@ -540,7 +534,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val triggerPhaseHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun triggerPhase( params: SubscriptionTriggerPhaseParams, @@ -559,7 +552,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { triggerPhaseHandler.handle(it) } .also { @@ -572,7 +565,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val unscheduleCancellationHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun unscheduleCancellation( params: SubscriptionUnscheduleCancellationParams, @@ -595,7 +587,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { unscheduleCancellationHandler.handle(it) } .also { @@ -608,7 +600,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val unscheduleFixedFeeQuantityUpdatesHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun unscheduleFixedFeeQuantityUpdates( params: SubscriptionUnscheduleFixedFeeQuantityUpdatesParams, @@ -631,7 +622,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { unscheduleFixedFeeQuantityUpdatesHandler.handle(it) } .also { @@ -644,7 +635,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val unschedulePendingPlanChangesHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun unschedulePendingPlanChanges( params: SubscriptionUnschedulePendingPlanChangesParams, @@ -667,7 +657,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { unschedulePendingPlanChangesHandler.handle(it) } .also { @@ -680,7 +670,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val updateFixedFeeQuantityHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun updateFixedFeeQuantity( params: SubscriptionUpdateFixedFeeQuantityParams, @@ -703,7 +692,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateFixedFeeQuantityHandler.handle(it) } .also { @@ -716,7 +705,6 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl private val updateTrialHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun updateTrial( params: SubscriptionUpdateTrialParams, @@ -735,7 +723,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateTrialHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/TopLevelServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/TopLevelServiceImpl.kt index 4777c1daf..22b1ecc21 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/TopLevelServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/TopLevelServiceImpl.kt @@ -3,13 +3,13 @@ package com.withorb.api.services.blocking import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -40,7 +40,8 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopLevelService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -51,7 +52,6 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client private val pingHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun ping( params: TopLevelPingParams, @@ -66,7 +66,7 @@ class TopLevelServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { pingHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceImpl.kt index b8a853001..c6c1c9f1d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/beta/ExternalPlanIdServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.beta import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -60,7 +60,8 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -70,7 +71,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: ) private val createPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun createPlanVersion( params: BetaExternalPlanIdCreatePlanVersionParams, @@ -89,7 +90,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createPlanVersionHandler.handle(it) } .also { @@ -101,7 +102,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: } private val fetchPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun fetchPlanVersion( params: BetaExternalPlanIdFetchPlanVersionParams, @@ -125,7 +126,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchPlanVersionHandler.handle(it) } .also { @@ -137,7 +138,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: } private val setDefaultPlanVersionHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun setDefaultPlanVersion( params: BetaExternalPlanIdSetDefaultPlanVersionParams, @@ -161,7 +162,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { setDefaultPlanVersionHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt index cea270e5c..7b05ab124 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/coupons/SubscriptionServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.coupons import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -43,7 +43,8 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : SubscriptionService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -53,7 +54,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl ) private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: CouponSubscriptionListParams, @@ -71,7 +72,7 @@ class SubscriptionServiceImpl internal constructor(private val clientOptions: Cl .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt index d36195843..581300c3a 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/BalanceTransactionServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.customers import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -53,7 +53,8 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BalanceTransactionService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -64,7 +65,6 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: CustomerBalanceTransactionCreateParams, @@ -83,7 +83,7 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -96,7 +96,6 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerBalanceTransactionListParams, @@ -114,7 +113,7 @@ class BalanceTransactionServiceImpl internal constructor(private val clientOptio .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostServiceImpl.kt index 822c9de8a..9eedcf79f 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CostServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.customers import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -50,7 +50,8 @@ class CostServiceImpl internal constructor(private val clientOptions: ClientOpti class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CostService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -61,7 +62,6 @@ class CostServiceImpl internal constructor(private val clientOptions: ClientOpti private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCostListParams, @@ -79,7 +79,7 @@ class CostServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -92,7 +92,6 @@ class CostServiceImpl internal constructor(private val clientOptions: ClientOpti private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCostListByExternalIdParams, @@ -115,7 +114,7 @@ class CostServiceImpl internal constructor(private val clientOptions: ClientOpti .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt index a3040e3be..ae2dfe22c 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/CreditServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.customers import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -65,7 +65,8 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : CreditService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) private val ledger: LedgerService.WithRawResponse by lazy { LedgerServiceImpl.WithRawResponseImpl(clientOptions) @@ -88,7 +89,6 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCreditListParams, @@ -106,7 +106,7 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -126,7 +126,6 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCreditListByExternalIdParams, @@ -149,7 +148,7 @@ class CreditServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt index 6ff494d21..d1e4410ff 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/LedgerServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.customers.credits import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -72,7 +72,8 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : LedgerService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -83,7 +84,6 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCreditLedgerListParams, @@ -101,7 +101,7 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -121,7 +121,6 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp private val createEntryHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun createEntry( params: CustomerCreditLedgerCreateEntryParams, @@ -140,7 +139,7 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createEntryHandler.handle(it) } .also { @@ -154,9 +153,8 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp private val createEntryByExternalIdHandler: Handler = jsonHandler( - clientOptions.jsonMapper - ) - .withErrorHandler(errorHandler) + clientOptions.jsonMapper + ) override fun createEntryByExternalId( params: CustomerCreditLedgerCreateEntryByExternalIdParams, @@ -181,7 +179,7 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createEntryByExternalIdHandler.handle(it) } .also { @@ -195,7 +193,6 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCreditLedgerListByExternalIdParams, @@ -219,7 +216,7 @@ class LedgerServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt index 2ab5a1d6f..80592386d 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/customers/credits/TopUpServiceImpl.kt @@ -3,13 +3,12 @@ package com.withorb.api.services.blocking.customers.credits import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired import com.withorb.api.core.handlers.emptyHandler +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest import com.withorb.api.core.http.HttpResponse @@ -89,7 +88,8 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : TopUpService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -100,7 +100,6 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: CustomerCreditTopUpCreateParams, @@ -119,7 +118,7 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -132,7 +131,6 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: CustomerCreditTopUpListParams, @@ -150,7 +148,7 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -168,7 +166,7 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val deleteHandler: Handler = emptyHandler().withErrorHandler(errorHandler) + private val deleteHandler: Handler = emptyHandler() override fun delete( params: CustomerCreditTopUpDeleteParams, @@ -193,13 +191,14 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { response.use { deleteHandler.handle(it) } } + return errorHandler.handle(response).parseable { + response.use { deleteHandler.handle(it) } + } } private val createByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun createByExternalId( params: CustomerCreditTopUpCreateByExternalIdParams, @@ -224,7 +223,7 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createByExternalIdHandler.handle(it) } .also { @@ -235,8 +234,7 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt } } - private val deleteByExternalIdHandler: Handler = - emptyHandler().withErrorHandler(errorHandler) + private val deleteByExternalIdHandler: Handler = emptyHandler() override fun deleteByExternalId( params: CustomerCreditTopUpDeleteByExternalIdParams, @@ -262,13 +260,14 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { response.use { deleteByExternalIdHandler.handle(it) } } + return errorHandler.handle(response).parseable { + response.use { deleteByExternalIdHandler.handle(it) } + } } private val listByExternalIdHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun listByExternalId( params: CustomerCreditTopUpListByExternalIdParams, @@ -292,7 +291,7 @@ class TopUpServiceImpl internal constructor(private val clientOptions: ClientOpt .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listByExternalIdHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceImpl.kt index adf741561..04b95cdf0 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/dimensionalPriceGroups/ExternalDimensionalPriceGroupIdServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.dimensionalPriceGroups import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -49,7 +49,8 @@ internal constructor(private val clientOptions: ClientOptions) : class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalDimensionalPriceGroupIdService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -60,7 +61,6 @@ internal constructor(private val clientOptions: ClientOptions) : private val retrieveHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun retrieve( params: DimensionalPriceGroupExternalDimensionalPriceGroupIdRetrieveParams, @@ -85,7 +85,7 @@ internal constructor(private val clientOptions: ClientOptions) : .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { retrieveHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt index 7e5ab2da5..4e5f90e1b 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/BackfillServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.events import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -80,7 +80,8 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : BackfillService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -91,7 +92,6 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun create( params: EventBackfillCreateParams, @@ -107,7 +107,7 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { createHandler.handle(it) } .also { @@ -120,7 +120,6 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun list( params: EventBackfillListParams, @@ -135,7 +134,7 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { @@ -155,7 +154,6 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client private val closeHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun close( params: EventBackfillCloseParams, @@ -174,7 +172,7 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { closeHandler.handle(it) } .also { @@ -187,7 +185,6 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun fetch( params: EventBackfillFetchParams, @@ -205,7 +202,7 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { @@ -218,7 +215,6 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client private val revertHandler: Handler = jsonHandler(clientOptions.jsonMapper) - .withErrorHandler(errorHandler) override fun revert( params: EventBackfillRevertParams, @@ -237,7 +233,7 @@ class BackfillServiceImpl internal constructor(private val clientOptions: Client .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { revertHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/VolumeServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/VolumeServiceImpl.kt index 7795f0048..5f8b4f8f5 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/VolumeServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/events/VolumeServiceImpl.kt @@ -3,13 +3,13 @@ package com.withorb.api.services.blocking.events import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.parseable @@ -37,7 +37,8 @@ class VolumeServiceImpl internal constructor(private val clientOptions: ClientOp class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : VolumeService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -47,7 +48,7 @@ class VolumeServiceImpl internal constructor(private val clientOptions: ClientOp ) private val listHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + jsonHandler(clientOptions.jsonMapper) override fun list( params: EventVolumeListParams, @@ -62,7 +63,7 @@ class VolumeServiceImpl internal constructor(private val clientOptions: ClientOp .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { listHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdServiceImpl.kt index 5f49584c7..632faabfd 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/plans/ExternalPlanIdServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.plans import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -51,7 +51,8 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalPlanIdService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -60,8 +61,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: clientOptions.toBuilder().apply(modifier::accept).build() ) - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PlanExternalPlanIdUpdateParams, @@ -80,7 +80,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -91,8 +91,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PlanExternalPlanIdFetchParams, @@ -110,7 +109,7 @@ class ExternalPlanIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/prices/ExternalPriceIdServiceImpl.kt b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/prices/ExternalPriceIdServiceImpl.kt index ddcaf01b4..af5d6859f 100644 --- a/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/prices/ExternalPriceIdServiceImpl.kt +++ b/orb-java-core/src/main/kotlin/com/withorb/api/services/blocking/prices/ExternalPriceIdServiceImpl.kt @@ -3,14 +3,14 @@ package com.withorb.api.services.blocking.prices import com.withorb.api.core.ClientOptions -import com.withorb.api.core.JsonValue import com.withorb.api.core.RequestOptions import com.withorb.api.core.checkRequired +import com.withorb.api.core.handlers.errorBodyHandler import com.withorb.api.core.handlers.errorHandler import com.withorb.api.core.handlers.jsonHandler -import com.withorb.api.core.handlers.withErrorHandler import com.withorb.api.core.http.HttpMethod import com.withorb.api.core.http.HttpRequest +import com.withorb.api.core.http.HttpResponse import com.withorb.api.core.http.HttpResponse.Handler import com.withorb.api.core.http.HttpResponseFor import com.withorb.api.core.http.json @@ -51,7 +51,8 @@ class ExternalPriceIdServiceImpl internal constructor(private val clientOptions: class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : ExternalPriceIdService.WithRawResponse { - private val errorHandler: Handler = errorHandler(clientOptions.jsonMapper) + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) override fun withOptions( modifier: Consumer @@ -60,8 +61,7 @@ class ExternalPriceIdServiceImpl internal constructor(private val clientOptions: clientOptions.toBuilder().apply(modifier::accept).build() ) - private val updateHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val updateHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun update( params: PriceExternalPriceIdUpdateParams, @@ -80,7 +80,7 @@ class ExternalPriceIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { updateHandler.handle(it) } .also { @@ -91,8 +91,7 @@ class ExternalPriceIdServiceImpl internal constructor(private val clientOptions: } } - private val fetchHandler: Handler = - jsonHandler(clientOptions.jsonMapper).withErrorHandler(errorHandler) + private val fetchHandler: Handler = jsonHandler(clientOptions.jsonMapper) override fun fetch( params: PriceExternalPriceIdFetchParams, @@ -110,7 +109,7 @@ class ExternalPriceIdServiceImpl internal constructor(private val clientOptions: .prepare(clientOptions, params) val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) - return response.parseable { + return errorHandler.handle(response).parseable { response .use { fetchHandler.handle(it) } .also { diff --git a/orb-java-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt b/orb-java-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt index 108484947..591b40a6a 100644 --- a/orb-java-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt +++ b/orb-java-core/src/test/kotlin/com/withorb/api/services/ErrorHandlingTest.kt @@ -157,18 +157,570 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun customersCreate400WithRawResponse() { + val customerService = client.customers().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(400).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(400) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun customersCreate401() { val customerService = client.customers() stubFor( post(anyUrl()) .willReturn( - status(401).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + status(401).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(401) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + + @Test + fun customersCreate401WithRawResponse() { + val customerService = client.customers().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(401).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(401) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + + @Test + fun customersCreate403() { + val customerService = client.customers() + stubFor( + post(anyUrl()) + .willReturn( + status(403).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(403) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + + @Test + fun customersCreate403WithRawResponse() { + val customerService = client.customers().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(403).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(403) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + + @Test + fun customersCreate404() { + val customerService = client.customers() + stubFor( + post(anyUrl()) + .willReturn( + status(404).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(404) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + + @Test + fun customersCreate404WithRawResponse() { + val customerService = client.customers().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(404).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) ) ) val e = - assertThrows { + assertThrows { customerService.create( CustomerCreateParams.builder() .email("dev@stainless.com") @@ -244,23 +796,23 @@ internal class ErrorHandlingTest { ) } - assertThat(e.statusCode()).isEqualTo(401) + assertThat(e.statusCode()).isEqualTo(404) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test - fun customersCreate403() { + fun customersCreate422() { val customerService = client.customers() stubFor( post(anyUrl()) .willReturn( - status(403).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + status(422).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) ) ) val e = - assertThrows { + assertThrows { customerService.create( CustomerCreateParams.builder() .email("dev@stainless.com") @@ -336,23 +888,23 @@ internal class ErrorHandlingTest { ) } - assertThat(e.statusCode()).isEqualTo(403) + assertThat(e.statusCode()).isEqualTo(422) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test - fun customersCreate404() { - val customerService = client.customers() + fun customersCreate422WithRawResponse() { + val customerService = client.customers().withRawResponse() stubFor( post(anyUrl()) .willReturn( - status(404).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + status(422).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) ) ) val e = - assertThrows { + assertThrows { customerService.create( CustomerCreateParams.builder() .email("dev@stainless.com") @@ -428,23 +980,23 @@ internal class ErrorHandlingTest { ) } - assertThat(e.statusCode()).isEqualTo(404) + assertThat(e.statusCode()).isEqualTo(422) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test - fun customersCreate422() { + fun customersCreate429() { val customerService = client.customers() stubFor( post(anyUrl()) .willReturn( - status(422).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + status(429).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) ) ) val e = - assertThrows { + assertThrows { customerService.create( CustomerCreateParams.builder() .email("dev@stainless.com") @@ -520,14 +1072,14 @@ internal class ErrorHandlingTest { ) } - assertThat(e.statusCode()).isEqualTo(422) + assertThat(e.statusCode()).isEqualTo(429) assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) assertThat(e.body()).isEqualTo(ERROR_JSON) } @Test - fun customersCreate429() { - val customerService = client.customers() + fun customersCreate429WithRawResponse() { + val customerService = client.customers().withRawResponse() stubFor( post(anyUrl()) .willReturn( @@ -709,6 +1261,98 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun customersCreate500WithRawResponse() { + val customerService = client.customers().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(500).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(500) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun customersCreate999() { val customerService = client.customers() @@ -801,6 +1445,98 @@ internal class ErrorHandlingTest { assertThat(e.body()).isEqualTo(ERROR_JSON) } + @Test + fun customersCreate999WithRawResponse() { + val customerService = client.customers().withRawResponse() + stubFor( + post(anyUrl()) + .willReturn( + status(999).withHeader(HEADER_NAME, HEADER_VALUE).withBody(ERROR_JSON_BYTES) + ) + ) + + val e = + assertThrows { + customerService.create( + CustomerCreateParams.builder() + .email("dev@stainless.com") + .name("x") + .accountingSyncConfiguration( + NewAccountingSyncConfiguration.builder() + .addAccountingProvider( + AccountingProviderConfig.builder() + .externalProviderId("external_provider_id") + .providerType("provider_type") + .build() + ) + .excluded(true) + .build() + ) + .addAdditionalEmail("dev@stainless.com") + .autoCollection(true) + .billingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .currency("currency") + .emailDelivery(true) + .externalCustomerId("external_customer_id") + .hierarchy( + CustomerHierarchyConfig.builder() + .addChildCustomerId("string") + .parentCustomerId("parent_customer_id") + .build() + ) + .metadata( + CustomerCreateParams.Metadata.builder() + .putAdditionalProperty("foo", JsonValue.from("string")) + .build() + ) + .paymentProvider(CustomerCreateParams.PaymentProvider.QUICKBOOKS) + .paymentProviderId("payment_provider_id") + .reportingConfiguration( + NewReportingConfiguration.builder().exempt(true).build() + ) + .shippingAddress( + AddressInput.builder() + .city("city") + .country("country") + .line1("line1") + .line2("line2") + .postalCode("postal_code") + .state("state") + .build() + ) + .taxConfiguration( + NewAvalaraTaxConfiguration.builder() + .taxExempt(true) + .taxProvider(NewAvalaraTaxConfiguration.TaxProvider.AVALARA) + .taxExemptionCode("tax_exemption_code") + .build() + ) + .taxId( + CustomerTaxId.builder() + .country(CustomerTaxId.Country.AD) + .type(CustomerTaxId.Type.AD_NRT) + .value("value") + .build() + ) + .timezone("timezone") + .build() + ) + } + + assertThat(e.statusCode()).isEqualTo(999) + assertThat(e.headers().toMap()).contains(entry(HEADER_NAME, listOf(HEADER_VALUE))) + assertThat(e.body()).isEqualTo(ERROR_JSON) + } + @Test fun customersCreateInvalidJsonBody() { val customerService = client.customers()