sttp icon indicating copy to clipboard operation
sttp copied to clipboard

Issue when response code is something other than 200

Open chrisbartoloburlo opened this issue 3 years ago • 5 comments

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: )

chrisbartoloburlo avatar Mar 21 '22 09:03 chrisbartoloburlo

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

Pask423 avatar Mar 21 '22 19:03 Pask423

Yes, I am using the sbt-openapi-generator.

chrisbartoloburlo avatar Mar 21 '22 20:03 chrisbartoloburlo

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 avatar Mar 21 '22 20:03 Pask423

@Pask423 Question: Would just ignore also solve the issue instead of asJson[Option[Unit]] or asEither(asString, ignore)?

chrisbartoloburlo avatar Mar 24 '22 09:03 chrisbartoloburlo

Yes it seems to also be an option here

Pask423 avatar Mar 24 '22 14:03 Pask423

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.

Pask423 avatar Oct 29 '22 20:10 Pask423