Skip to content

Commit e1df3c5

Browse files
committed
add empty response handler
1 parent 8d77ed4 commit e1df3c5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

modules/core/shared/src/main/scala/codegen.scala

+17-3
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ def generateBySpec(
207207
| asStringAlways.mapWithMetadata((body, metadata) =>
208208
| if metadata.isSuccess then body.fromJson[T].left.map(e => DeserializationException(body, Exception(e)))
209209
| else Left(HttpError(body, metadata.code))
210+
| )""".stripMargin,
211+
"",
212+
config.httpSource match
213+
case HttpSource.Sttp4 =>
214+
"""|def asEmptyResponse: ResponseAs[Either[ResponseException[String], String]] =
215+
| asStringAlways.mapWithMetadata((body, metadata) =>
216+
| if metadata.isSuccess then Right(body)
217+
| else Left(UnexpectedStatusCode(body, metadata))
218+
| )""".stripMargin
219+
case HttpSource.Sttp3 =>
220+
"""|def asEmptyResponse: ResponseAs[Either[ResponseException[String, Exception], String], Any] =
221+
| asStringAlways.mapWithMetadata((body, metadata) =>
222+
| if metadata.isSuccess then Right(body)
223+
| else Left(HttpError(body, metadata.code))
210224
| )""".stripMargin
211225
).mkString("\n")
212226
)
@@ -402,9 +416,9 @@ def resourceCode(
402416
def responseType(t: String) =
403417
httpSource match
404418
case HttpSource.Sttp4 =>
405-
s"Request[Either[${if t == "String" then "String" else "ResponseException[String]"}, $t]]"
419+
s"Request[Either[ResponseException[String], $t]]"
406420
case HttpSource.Sttp3 =>
407-
s"RequestT[Identity, Either[${if t == "String" then "String" else "ResponseException[String, Exception]"}, $t], Any]"
421+
s"RequestT[Identity, Either[ResponseException[String, Exception], $t], Any]"
408422

409423
val (resType, mapResponse) = v.response match
410424
case Some(r) if r.schemaPath.forall(hasProps) =>
@@ -414,7 +428,7 @@ def resourceCode(
414428
responseType(bodyType),
415429
s".response(asJson[$bodyType])"
416430
)
417-
case _ => (responseType("String"), "")
431+
case _ => (responseType("String"), ".response(asEmptyResponse)")
418432

419433
s"""|def ${toScalaName(k)}(\n${params.mkString(",\n")}): $resType = {$queryParams
420434
| $setReqUri

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.10.10
1+
sbt.version=1.10.11

0 commit comments

Comments
 (0)