Skip to content

Commit

Permalink
[kotlin] Change Kotlin client exceptions to expose lack of support as…
Browse files Browse the repository at this point in the history
… UnsupportedOperationException rather than NotImplementedException. (#3611)

* [kotlin] Throw catchable exceptions rather than TODO()

* [kotlin] Regenerate samples
  • Loading branch information
jimschubert authored Aug 13, 2019
1 parent 93aedcf commit b936d72
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class {{classname}}(basePath: kotlin.String = "{{{basePath}}}") : ApiClient(base

return when (response.responseType) {
ResponseType.Success -> {{#returnType}}(response as Success<*>).data as {{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ open class ApiClient(val baseUrl: String) {
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
mediaType.toMediaTypeOrNull()
)
mediaType == XmlMediaType -> TODO("xml not currently supported.")
mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.")
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
}
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
Expand All @@ -61,7 +61,7 @@ open class ApiClient(val baseUrl: String) {
}
return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.")
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -82,8 +82,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -113,8 +113,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -144,8 +144,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.Array<Pet>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -175,8 +175,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Pet
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -205,8 +205,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -237,8 +237,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -270,8 +270,8 @@ class PetApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCli

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as ApiResponse
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -80,8 +80,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.collections.Map<kotlin.String, kotlin.Int>
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -111,8 +111,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -142,8 +142,8 @@ class StoreApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiC

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as Order
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -80,8 +80,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -110,8 +110,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -140,8 +140,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -171,8 +171,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as User
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -203,8 +203,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> (response as Success<*>).data as kotlin.String
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -232,8 +232,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down Expand Up @@ -263,8 +263,8 @@ class UserApi(basePath: kotlin.String = "http://petstore.swagger.io/v2") : ApiCl

return when (response.responseType) {
ResponseType.Success -> Unit
ResponseType.Informational -> TODO()
ResponseType.Redirection -> TODO()
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
ResponseType.ClientError -> throw ClientException((response as ClientError<*>).body as? String ?: "Client error")
ResponseType.ServerError -> throw ServerException((response as ServerError<*>).message ?: "Server error")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ open class ApiClient(val baseUrl: String) {
mediaType == JsonMediaType -> Serializer.moshi.adapter(T::class.java).toJson(content).toRequestBody(
mediaType.toMediaTypeOrNull()
)
mediaType == XmlMediaType -> TODO("xml not currently supported.")
mediaType == XmlMediaType -> throw UnsupportedOperationException("xml not currently supported.")
// TODO: this should be extended with other serializers
else -> TODO("requestBody currently only supports JSON body and File body.")
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
}

protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
Expand All @@ -61,7 +61,7 @@ open class ApiClient(val baseUrl: String) {
}
return when(mediaType) {
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
else -> TODO("responseBody currently only supports JSON body.")
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
}
}

Expand Down
Loading

0 comments on commit b936d72

Please # to comment.