diff --git a/src/main/scala/ch/chuv/lren/woken/api/MetadataWebService.scala b/src/main/scala/ch/chuv/lren/woken/api/MetadataWebService.scala index 829157ce..bf40b8de 100644 --- a/src/main/scala/ch/chuv/lren/woken/api/MetadataWebService.scala +++ b/src/main/scala/ch/chuv/lren/woken/api/MetadataWebService.scala @@ -40,7 +40,7 @@ class MetadataApiService( )(implicit system: ActorSystem) extends MetadataServiceApi with SprayJsonSupport - with RouteHelpers + with SecuredRouteHelper with WebsocketSupport with LazyLogging { diff --git a/src/main/scala/ch/chuv/lren/woken/api/MiningWebService.scala b/src/main/scala/ch/chuv/lren/woken/api/MiningWebService.scala index 7f4e7d18..b424cad3 100644 --- a/src/main/scala/ch/chuv/lren/woken/api/MiningWebService.scala +++ b/src/main/scala/ch/chuv/lren/woken/api/MiningWebService.scala @@ -50,7 +50,7 @@ class MiningWebService( with DefaultJsonProtocol with SprayJsonSupport with PredefinedToResponseMarshallers - with RouteHelpers + with SecuredRouteHelper with WebsocketSupport with LazyLogging { diff --git a/src/main/scala/ch/chuv/lren/woken/api/WebsocketSupport.scala b/src/main/scala/ch/chuv/lren/woken/api/WebsocketSupport.scala index ef151c2f..eb2b07ce 100644 --- a/src/main/scala/ch/chuv/lren/woken/api/WebsocketSupport.scala +++ b/src/main/scala/ch/chuv/lren/woken/api/WebsocketSupport.scala @@ -42,7 +42,8 @@ import com.typesafe.scalalogging.LazyLogging import scala.util.{ Failure, Success, Try } -trait WebsocketSupport extends LazyLogging { +trait WebsocketSupport { + this: LazyLogging => val masterRouter: ActorRef val featuresDatabase: FeaturesDAL diff --git a/src/main/scala/ch/chuv/lren/woken/api/services.scala b/src/main/scala/ch/chuv/lren/woken/api/services.scala index 9fa02520..f754d2ea 100644 --- a/src/main/scala/ch/chuv/lren/woken/api/services.scala +++ b/src/main/scala/ch/chuv/lren/woken/api/services.scala @@ -17,7 +17,7 @@ package ch.chuv.lren.woken.api -import akka.http.scaladsl.model.{ HttpEntity, StatusCode, StatusCodes } +import akka.http.scaladsl.model.{ StatusCode, StatusCodes } import akka.http.scaladsl.server._ import StatusCodes._ import akka.http.scaladsl.model.ws.{ Message, UpgradeToWebSocket } @@ -29,15 +29,6 @@ import com.typesafe.scalalogging.LazyLogging import scala.concurrent.ExecutionContext import scala.util.Failure -/** - * Holds potential error response with the HTTP status and optional body - * - * @param responseStatus the status code - * @param response the optional body - */ -case class ErrorResponseException(responseStatus: StatusCode, response: Option[HttpEntity]) - extends Exception - /** * Provides a hook to catch exceptions and rejections from routes, allowing custom * responses to be provided, logs to be captured, and potentially remedial actions. @@ -46,6 +37,7 @@ case class ErrorResponseException(responseStatus: StatusCode, response: Option[H * JSON API (e.g. see how Foursquare do it). */ trait FailureHandling { + this: LazyLogging => implicit def rejectionHandler: RejectionHandler = RejectionHandler.default @@ -56,7 +48,7 @@ trait FailureHandling { loggedFailureResponse( ctx, e, - message = "The server was asked a question that didn't make sense: " + e.getMessage, + message = s"The server was asked a question that didn't make sense: ${e.getMessage}", error = StatusCodes.NotAcceptable ) @@ -80,13 +72,16 @@ trait FailureHandling { thrown: Throwable, message: String = "The server is having problems.", error: StatusCode = StatusCodes.InternalServerError - ) = - //log.error(thrown, ctx.request.toString) + ) = { + logger.error(ctx.request.toString, thrown) ctx.complete((error, message)) + } } -trait RouteHelpers extends BasicAuthenticator with Directives with LazyLogging { +trait SecuredRouteHelper extends BasicAuthenticator with Directives { + this: LazyLogging => + implicit val executionContext: ExecutionContext implicit val timeout: Timeout