diff options
author | zachdriver <zach@driver.xyz> | 2018-05-09 14:50:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-09 14:50:03 -0700 |
commit | b844c843f3b4433b37ddd2d7e8c10a183c47ca08 (patch) | |
tree | 893a7860724a0b368dbc3f7bff9072b4e1dc600b /src/main/scala | |
parent | 6fde5b828ee0f131536d0df0caf68e712742de53 (diff) | |
download | driver-core-1.9.1.tar.gz driver-core-1.9.1.tar.bz2 driver-core-1.9.1.zip |
API-1595 Move rejectionHandler to DriverApp to avoid 404 rejection issues (#167)v1.9.1
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/app/DriverApp.scala | 11 | ||||
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/DriverRoute.scala | 12 |
2 files changed, 11 insertions, 12 deletions
diff --git a/src/main/scala/xyz/driver/core/app/DriverApp.scala b/src/main/scala/xyz/driver/core/app/DriverApp.scala index bf18c3d..56ee898 100644 --- a/src/main/scala/xyz/driver/core/app/DriverApp.scala +++ b/src/main/scala/xyz/driver/core/app/DriverApp.scala @@ -127,7 +127,7 @@ class DriverApp( val combinedRoute = Route.seal(modules.map(_.route).foldLeft(basicRoutes.routeWithDefaults)(_ ~ _) ~ defaultOptionsRoute) - (extractHost & extractClientIP & trace(tracer)) { + (extractHost & extractClientIP & trace(tracer) & handleRejections(authenticationRejectionHandler)) { case (origin, ip) => ctx => val trackingId = extractTrackingId(ctx.request) @@ -153,6 +153,15 @@ class DriverApp( } } + protected def authenticationRejectionHandler: RejectionHandler = + RejectionHandler + .newBuilder() + .handle { + case AuthenticationFailedRejection(_, challenge) => + complete(HttpResponse(StatusCodes.Unauthorized, entity = challenge.realm)) + } + .result() + protected def bindHttp(modules: Seq[Module]): Unit = { val _ = http.bindAndHandle(route2HandlerFlow(appRoute), interface, port)(materializer) } diff --git a/src/main/scala/xyz/driver/core/rest/DriverRoute.scala b/src/main/scala/xyz/driver/core/rest/DriverRoute.scala index 538d918..c23c44d 100644 --- a/src/main/scala/xyz/driver/core/rest/DriverRoute.scala +++ b/src/main/scala/xyz/driver/core/rest/DriverRoute.scala @@ -19,8 +19,7 @@ trait DriverRoute { def route: Route def routeWithDefaults: Route = { - (defaultResponseHeaders & handleExceptions(ExceptionHandler(exceptionHandler)) & handleRejections( - authenticationRejectionHandler)) { + (defaultResponseHeaders & handleExceptions(ExceptionHandler(exceptionHandler))) { route } } @@ -98,13 +97,4 @@ trait DriverRoute { protected def errorResponse[T <: Exception](statusCode: StatusCode, message: String, exception: T): Route = { complete(HttpResponse(statusCode, entity = message)) } - - protected def authenticationRejectionHandler: RejectionHandler = - RejectionHandler - .newBuilder() - .handle { - case AuthenticationFailedRejection(_, challenge) => - complete(HttpResponse(StatusCodes.Unauthorized, entity = challenge.realm)) - } - .result() } |