From f16f855244cf9f98c9277f42830a116b11636591 Mon Sep 17 00:00:00 2001 From: Conor Gallagher Date: Tue, 19 Jul 2022 15:01:21 +0100 Subject: [PATCH] Throw Runtime exceptions. (#137) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The exception classes generated by Fabrikt for the client are not triggering Spring's [@Transactional](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html) to rollback transactions. This is because the Fabrikt generated exceptions extend Exception instead of RuntimeException. > In its default configuration, the Spring Framework’s transaction infrastructure code only marks a transaction for rollback in the case of runtime, unchecked exceptions; that is, when the thrown exception is an instance or subclass of RuntimeException. --- src/main/resources/templates/client-code/api-models.kt.hbs | 2 +- src/test/resources/examples/okHttpClient/client/ApiModels.kt | 2 +- .../examples/okHttpClientMultiMediaType/client/ApiModels.kt | 2 +- .../okHttpClientPostWithoutRequestBody/client/ApiModels.kt | 2 +- .../resources/examples/parameterNameClash/client/ApiModels.kt | 2 +- .../resources/examples/pathLevelParameters/client/ApiModels.kt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/templates/client-code/api-models.kt.hbs b/src/main/resources/templates/client-code/api-models.kt.hbs index 86c54001..421cb7fd 100644 --- a/src/main/resources/templates/client-code/api-models.kt.hbs +++ b/src/main/resources/templates/client-code/api-models.kt.hbs @@ -12,7 +12,7 @@ data class ApiResponse(val statusCode: Int, val headers: Headers, val data: T /** * API non-2xx failure responses returned by API call. */ -open class ApiException(override val message: String) : Exception(message) +open class ApiException(override val message: String) : RuntimeException(message) /** * API 4xx failure responses returned by API call. diff --git a/src/test/resources/examples/okHttpClient/client/ApiModels.kt b/src/test/resources/examples/okHttpClient/client/ApiModels.kt index 861c5071..a7a9ae30 100644 --- a/src/test/resources/examples/okHttpClient/client/ApiModels.kt +++ b/src/test/resources/examples/okHttpClient/client/ApiModels.kt @@ -12,7 +12,7 @@ data class ApiResponse(val statusCode: Int, val headers: Headers, val data: T /** * API non-2xx failure responses returned by API call. */ -open class ApiException(override val message: String) : Exception(message) +open class ApiException(override val message: String) : RuntimeException(message) /** * API 4xx failure responses returned by API call. diff --git a/src/test/resources/examples/okHttpClientMultiMediaType/client/ApiModels.kt b/src/test/resources/examples/okHttpClientMultiMediaType/client/ApiModels.kt index 3358c7d3..a4d96993 100644 --- a/src/test/resources/examples/okHttpClientMultiMediaType/client/ApiModels.kt +++ b/src/test/resources/examples/okHttpClientMultiMediaType/client/ApiModels.kt @@ -12,7 +12,7 @@ data class ApiResponse(val statusCode: Int, val headers: Headers, val data: T /** * API non-2xx failure responses returned by API call. */ -open class ApiException(override val message: String) : Exception(message) +open class ApiException(override val message: String) : RuntimeException(message) /** * API 4xx failure responses returned by API call. diff --git a/src/test/resources/examples/okHttpClientPostWithoutRequestBody/client/ApiModels.kt b/src/test/resources/examples/okHttpClientPostWithoutRequestBody/client/ApiModels.kt index ca59e3c3..df87b810 100644 --- a/src/test/resources/examples/okHttpClientPostWithoutRequestBody/client/ApiModels.kt +++ b/src/test/resources/examples/okHttpClientPostWithoutRequestBody/client/ApiModels.kt @@ -12,7 +12,7 @@ data class ApiResponse(val statusCode: Int, val headers: Headers, val data: T /** * API non-2xx failure responses returned by API call. */ -open class ApiException(override val message: String) : Exception(message) +open class ApiException(override val message: String) : RuntimeException(message) /** * API 4xx failure responses returned by API call. diff --git a/src/test/resources/examples/parameterNameClash/client/ApiModels.kt b/src/test/resources/examples/parameterNameClash/client/ApiModels.kt index e7de8131..d7f6bf62 100644 --- a/src/test/resources/examples/parameterNameClash/client/ApiModels.kt +++ b/src/test/resources/examples/parameterNameClash/client/ApiModels.kt @@ -12,7 +12,7 @@ data class ApiResponse(val statusCode: Int, val headers: Headers, val data: T /** * API non-2xx failure responses returned by API call. */ -open class ApiException(override val message: String) : Exception(message) +open class ApiException(override val message: String) : RuntimeException(message) /** * API 4xx failure responses returned by API call. diff --git a/src/test/resources/examples/pathLevelParameters/client/ApiModels.kt b/src/test/resources/examples/pathLevelParameters/client/ApiModels.kt index 8050e32c..0d3871e3 100644 --- a/src/test/resources/examples/pathLevelParameters/client/ApiModels.kt +++ b/src/test/resources/examples/pathLevelParameters/client/ApiModels.kt @@ -12,7 +12,7 @@ data class ApiResponse(val statusCode: Int, val headers: Headers, val data: T /** * API non-2xx failure responses returned by API call. */ -open class ApiException(override val message: String) : Exception(message) +open class ApiException(override val message: String) : RuntimeException(message) /** * API 4xx failure responses returned by API call.