diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache index 150fff84dbd..20070e1b86b 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/api.mustache @@ -73,11 +73,11 @@ import {{packageName}}.infrastructure.toMultiValue ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index 90080744c69..9a15406f1bb 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -237,12 +237,13 @@ import java.io.File response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() ) response.isClientError -> return ClientError( + response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(), response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() ) else -> return ServerError( - null, + response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(), response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiInfrastructureResponse.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiInfrastructureResponse.kt.mustache index 09e6301cee5..98be9afd5fb 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiInfrastructureResponse.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiInfrastructureResponse.kt.mustache @@ -4,7 +4,9 @@ package {{packageName}}.infrastructure Success, Informational, Redirection, ClientError, ServerError } -{{#nonPublicApi}}internal {{/nonPublicApi}}abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +{{#nonPublicApi}}internal {{/nonPublicApi}}interface Response + +{{#nonPublicApi}}internal {{/nonPublicApi}}abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ package {{packageName}}.infrastructure ) : ApiInfrastructureResponse(ResponseType.Redirection) {{#nonPublicApi}}internal {{/nonPublicApi}}class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/Errors.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/Errors.kt.mustache index 45b9a9e3f32..7c428ad655f 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/Errors.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/Errors.kt.mustache @@ -3,14 +3,14 @@ package {{packageName}}.infrastructure import java.lang.RuntimeException -{{#nonPublicApi}}internal {{/nonPublicApi}}open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +{{#nonPublicApi}}internal {{/nonPublicApi}}open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { {{#nonPublicApi}}internal {{/nonPublicApi}}companion object { private const val serialVersionUID: Long = 123L } } -{{#nonPublicApi}}internal {{/nonPublicApi}}open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +{{#nonPublicApi}}internal {{/nonPublicApi}}open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { {{#nonPublicApi}}internal {{/nonPublicApi}}companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1638d460c68..2e3b24ae2ea 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5dcfe386089..0907e471f43 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index cb72e1568f3..97248ed4cfd 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -190,11 +190,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -231,11 +231,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -271,11 +271,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -313,11 +313,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -356,11 +356,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index de65b44cd9a..d56cfcc2a32 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1638d460c68..2e3b24ae2ea 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5670d3c132b..a03ba02ff08 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index d4b862a21ae..51247617d9c 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ internal class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index f1b775deba8..893601a3220 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ internal class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2 ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 0703be33057..d486ee7dc52 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ internal class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2" ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index f786e8d0f2d..0055340ab35 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ internal open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index 6f38b7aa18c..c618544573e 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ internal enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -internal abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +internal interface Response + +internal abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ internal class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) internal class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 0c5925723b2..204b69dcb08 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -internal open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +internal open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { internal companion object { private const val serialVersionUID: Long = 123L } } -internal open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +internal open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { internal companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 3b1ecae4210..de4ab6dbb83 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 1a889435cd2..a2deaaa89d1 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 3c561969920..d4f2f9f8c24 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5670d3c132b..a03ba02ff08 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index 51c1f14b2a8..77066de4e55 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1638d460c68..2e3b24ae2ea 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9551a3a0c92..2669e67f34f 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -156,12 +156,13 @@ open class ApiClient(val baseUrl: String) { response.headers().toMultimap() ) response.isClientError -> return ClientError( + response.message(), response.body()?.string(), response.code(), response.headers().toMultimap() ) else -> return ServerError( - null, + response.message(), response.body()?.string(), response.code(), response.headers().toMultimap() diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index e475ddc88d8..69d1e725e49 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5670d3c132b..a03ba02ff08 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1638d460c68..2e3b24ae2ea 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5670d3c132b..a03ba02ff08 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt index 1638d460c68..2e3b24ae2ea 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/PetApi.kt @@ -59,11 +59,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -100,11 +100,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -144,11 +144,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -188,11 +188,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -229,11 +229,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -269,11 +269,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -311,11 +311,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -354,11 +354,11 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt index 18355b552ae..1399a0ca1cf 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/StoreApi.kt @@ -58,11 +58,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -139,11 +139,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -180,11 +180,11 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt index 4f18a92d223..a7d99762fd8 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/apis/UserApi.kt @@ -58,11 +58,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -98,11 +98,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -138,11 +138,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -178,11 +178,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -219,11 +219,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -265,11 +265,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -304,11 +304,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } @@ -345,11 +345,11 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") ResponseType.ClientError -> { val localVarError = localVarResponse as ClientError<*> - throw ClientException(localVarError.body as? String ?: "Client error", localVarError.statusCode) + throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } ResponseType.ServerError -> { val localVarError = localVarResponse as ServerError<*> - throw ServerException(localVarError.message ?: "Server error", localVarError.statusCode) + throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) } } } diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5670d3c132b..a03ba02ff08 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -158,12 +158,13 @@ open class ApiClient(val baseUrl: String) { response.headers.toMultimap() ) response.isClientError -> return ClientError( + response.message, response.body?.string(), response.code, response.headers.toMultimap() ) else -> return ServerError( - null, + response.message, response.body?.string(), response.code, response.headers.toMultimap() diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt index f1a8aecc914..9dc8d8dbbfa 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt @@ -4,7 +4,9 @@ enum class ResponseType { Success, Informational, Redirection, ClientError, ServerError } -abstract class ApiInfrastructureResponse(val responseType: ResponseType) { +interface Response + +abstract class ApiInfrastructureResponse(val responseType: ResponseType): Response { abstract val statusCode: Int abstract val headers: Map> } @@ -27,6 +29,7 @@ class Redirection( ) : ApiInfrastructureResponse(ResponseType.Redirection) class ClientError( + val message: String? = null, val body: Any? = null, override val statusCode: Int = -1, override val headers: Map> = mapOf() diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt index 41f529a5f36..b5310e71f13 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt @@ -3,14 +3,14 @@ package org.openapitools.client.infrastructure import java.lang.RuntimeException -open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ClientException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 123L } } -open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1) : RuntimeException(message) { +open class ServerException(message: kotlin.String? = null, val statusCode: Int = -1, val response: Response? = null) : RuntimeException(message) { companion object { private const val serialVersionUID: Long = 456L