From 8a525b723ea3cc9388a5399126f540616cd5619e Mon Sep 17 00:00:00 2001 From: vlad Date: Wed, 1 Feb 2017 12:12:32 -0500 Subject: Cleaned up core from Driver-specific roles and permissions, updated README todo items --- src/main/scala/xyz/driver/core/app.scala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/main/scala/xyz/driver/core/app.scala') diff --git a/src/main/scala/xyz/driver/core/app.scala b/src/main/scala/xyz/driver/core/app.scala index 9bc34f6..54d08d4 100644 --- a/src/main/scala/xyz/driver/core/app.scala +++ b/src/main/scala/xyz/driver/core/app.scala @@ -16,7 +16,8 @@ import org.slf4j.LoggerFactory import spray.json.DefaultJsonProtocol import xyz.driver.core import xyz.driver.core.logging.{Logger, TypesafeScalaLogger} -import xyz.driver.core.rest.{ContextHeaders, Swagger} +import xyz.driver.core.rest.ServiceRequestContext.ContextHeaders +import xyz.driver.core.rest.Swagger import xyz.driver.core.stats.SystemStats import xyz.driver.core.time.Time import xyz.driver.core.time.provider.{SystemTimeProvider, TimeProvider} @@ -68,7 +69,7 @@ object app { val _ = Future { http.bindAndHandle(route2HandlerFlow(handleExceptions(ExceptionHandler(exceptionHandler)) { ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.ServiceRequestContext.extractTrackingId(ctx) log.audit(s"Received request ${ctx.request} with tracking id $trackingId") val contextWithTrackingId = @@ -81,24 +82,29 @@ object app { } } + /** + * Override me for custom exception handling + * + * @return Exception handling route for exception type + */ protected def exceptionHandler = PartialFunction[Throwable, Route] { case is: IllegalStateException => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.ServiceRequestContext.extractTrackingId(ctx) log.debug(s"Request is not allowed to ${ctx.request.uri} ($trackingId)", is) complete(HttpResponse(BadRequest, entity = is.getMessage))(ctx) case cm: ConcurrentModificationException => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.ServiceRequestContext.extractTrackingId(ctx) log.audit(s"Concurrent modification of the resource ${ctx.request.uri} ($trackingId)", cm) complete( HttpResponse(Conflict, entity = "Resource was changed concurrently, try requesting a newer version"))(ctx) case t: Throwable => ctx => - val trackingId = rest.extractTrackingId(ctx) + val trackingId = rest.ServiceRequestContext.extractTrackingId(ctx) log.error(s"Request to ${ctx.request.uri} could not be handled normally ($trackingId)", t) complete(HttpResponse(InternalServerError, entity = t.getMessage))(ctx) } -- cgit v1.2.3