Skip to content

Commit

Permalink
Renamed route helper trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicc committed Mar 12, 2018
1 parent d80c1f8 commit 6745171
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MetadataApiService(
)(implicit system: ActorSystem)
extends MetadataServiceApi
with SprayJsonSupport
with RouteHelpers
with SecuredRouteHelper
with WebsocketSupport
with LazyLogging {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MiningWebService(
with DefaultJsonProtocol
with SprayJsonSupport
with PredefinedToResponseMarshallers
with RouteHelpers
with SecuredRouteHelper
with WebsocketSupport
with LazyLogging {

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/ch/chuv/lren/woken/api/WebsocketSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 9 additions & 14 deletions src/main/scala/ch/chuv/lren/woken/api/services.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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
)

Expand All @@ -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

Expand Down

0 comments on commit 6745171

Please sign in to comment.