Issue when response code is something other than 200
I keep getting an exception whenever the response is other than 200.
The requests are being sent as follows:
def addProduct(productName: String): ApiRequestT[Unit] =
basicRequest
.method(Method.POST, uri"$baseUrl/products/${productName}")
.contentType("application/json")
.response(asJson[Unit])
def deleteProductByName(productName: String): ApiRequestT[Unit] =
basicRequest
.method(Method.DELETE, uri"$baseUrl/products/${productName}")
.contentType("application/json")
.response(asJson[Unit])
And I am getting the following output:
Failure(org.openapitools.client.core.HttpException: [201] Created: )
Failure(org.openapitools.client.core.HttpException: [204] No Content: )
Do you use some generator for your endpoints ?
We have old issue related to 204 and asJson[Unit]
https://github.com/softwaremill/sttp/issues/675
Yes, I am using the sbt-openapi-generator.
ok, so it can be caused by same root issues as #675
Try asJson[Option[Unit]] or asEither(asString, ignore) or even https://github.com/ghostbuster91/sttp-openapi-generator
Maybe one of them will make sens for you.
@Pask423 Question: Would just ignore also solve the issue instead of asJson[Option[Unit]] or asEither(asString, ignore)?
Yes it seems to also be an option here
Seem to be fix in 6.2.0 of openapi-generator.
As for sbt managed generator I would advise using https://github.com/OpenAPITools/sbt-openapi-generator as one provided above is quite outdated.