Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed May 18, 2024
1 parent 603ca26 commit c33d068
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
15 changes: 2 additions & 13 deletions cask/src/cask/endpoints/JsonEndpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,10 @@ class postJson(val path: String, override val subpath: Boolean = false)
val methods = Seq("post")
type InputParser[T] = JsReader[T]

def wrapFunction(ctx: Request,
delegate: Delegate): Result[Response.Raw] = {
def wrapFunction(ctx: Request, delegate: Delegate): Result[Response.Raw] = {
val obj = for{
str <-
try {
val boas = new ByteArrayOutputStream()
Util.transferTo(ctx.exchange.getInputStream, boas)
Right(new String(boas.toByteArray))
}
catch{case e: Throwable => Left(cask.model.Response(
"Unable to deserialize input JSON text: " + e + "\n" + Util.stackTraceString(e),
statusCode = 400
))}
json <-
try Right(ujson.read(str))
try Right(ujson.read(ctx.exchange.getInputStream))
catch{case e: Throwable => Left(cask.model.Response(
"Input text is invalid JSON: " + e + "\n" + Util.stackTraceString(e),
statusCode = 400
Expand Down
1 change: 1 addition & 0 deletions example/httpMethods/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ trait AppModule extends CrossScalaModule{
ivy"com.lihaoyi::utest::0.8.1",
ivy"com.lihaoyi::requests::0.8.0",
)
def forkArgs = Seq("--add-opens=java.base/java.net=ALL-UNNAMED")
}
}

0 comments on commit c33d068

Please sign in to comment.