Skip to content

Commit

Permalink
Better errors (#18)
Browse files Browse the repository at this point in the history
* return explanation why the request wasn't successful

* don't match the route if serviceName is missing
  • Loading branch information
augi authored Aug 15, 2018
1 parent 57f84f5 commit cd2712a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ object AkkaHttp {
}
}

case None => complete(StatusCodes.NotFound)
case None => complete(StatusCodes.NotFound, s"Service '$serviceName' not found")
}

case _ =>
complete(StatusCodes.BadRequest)
complete(StatusCodes.BadRequest, s"Content-Type must be '$JsonContentType'")
}
}
}
Expand All @@ -73,7 +73,7 @@ object AkkaHttp {
case Some(service) =>
complete(service.methodsNames.mkString("\n"))

case None => complete(StatusCodes.NotFound)
case None => complete(StatusCodes.NotFound, s"Service '$serviceName' not found")
}
}
} ~ get {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ object Http4s extends StrictLogging {
logger.info(s"Creating HTTP4S service proxying gRPC services: ${bridges.map(_.serviceName).mkString("[", ", ", "]")}")

val http4sService = HttpService[IO] {
case _ @ GET -> `pathPrefix` / serviceName =>
case _ @ GET -> `pathPrefix` / serviceName if serviceName.nonEmpty =>
services.get(serviceName) match {
case Some(service) =>
Ok {
service.methodsNames.mkString("\n")
}

case None => NotFound()
case None => NotFound(s"Service '$serviceName' not found")
}

case _ @ GET -> `pathPrefix` =>
Expand All @@ -62,10 +62,10 @@ object Http4s extends StrictLogging {
case Left(st) => mapStatus(st, configuration)
}

case None => NotFound()
case None => NotFound(s"Service '$serviceName' not found")
}

case _ => BadRequest()
case _ => BadRequest(s"Content-Type must be '$JsonContentType'")
}
}

Expand Down

0 comments on commit cd2712a

Please sign in to comment.