--- a/src/main/scala/Main.scala Sun Sep 04 15:07:07 2011 -0400
+++ b/src/main/scala/Main.scala Sun Sep 04 15:16:36 2011 -0400
@@ -44,7 +44,7 @@
Ok ~> ViaSPARQL ~> ContentType("text/html") ~> ResponseString(body)
}
case GET(_) | HEAD(_) => {
- val result = for {
+ val response = for {
model <- r.get() failMap { x => NotFound }
encoding = RDFEncoding(req)
} yield {
@@ -53,16 +53,14 @@
case HEAD(_) => Ok ~> ViaSPARQL ~> ContentType(encoding.toContentType)
}
}
- result.fold(f => f, s => s)
+ response.fold(f => f, s => s)
}
case PUT(_) => {
val response = for {
- bodyModel <- modelFromInputStream(Body.stream(req), baseURI)
- _ <- r.save(bodyModel)
+ bodyModel <- modelFromInputStream(Body.stream(req), baseURI) failMap { t => BadRequest ~> ResponseString(t.getStackTraceString) }
+ _ <- r.save(bodyModel) failMap { t => InternalServerError ~> ResponseString(t.getStackTraceString) }
} yield Created
- response.fold(
- t => InternalServerError ~> ResponseString(t.getStackTraceString),
- s => s)
+ response.fold(f => f, s => s)
}
case POST(_) => {
Post.parse(Body.stream(req), baseURI) match {
--- a/src/test/scala/Test.scala Sun Sep 04 15:07:07 2011 -0400
+++ b/src/test/scala/Test.scala Sun Sep 04 15:16:36 2011 -0400
@@ -195,6 +195,13 @@
statusCode must_== 400
}
}
+
+ """PUTting not-valid RDF to Joe's URI""" should {
+ "return a 400 Bad Request" in {
+ val statusCode = Http.when(_ == 400)(joe.put("that's bouleshit") get_statusCode)
+ statusCode must_== 400
+ }
+ }
"""a DELETE request""" should {
"not be supported yet" in {