Created
July 17, 2015 08:24
-
-
Save magnusart/a3b9321d6e391889d59a to your computer and use it in GitHub Desktop.
Route DSL type errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] found : akka.http.scaladsl.server.RequestContext => scala.concurrent.Future[akka.http.scaladsl.server.RouteResult] | |
[error] required: scala.concurrent.Future[akka.http.scaladsl.server.RouteResult] | |
[error] eitherRejectionAsync( upload( ctx.request ) )( executionContext ) { response: HttpResponse ⇒ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def eitherRejection[T]( result: Either[Rejection, T] ): Directive1[T] = result match { | |
case Left( rej ) ⇒ reject( rej ) | |
case Right( t ) ⇒ provide( t ) | |
} | |
def eitherRejectionAsync[T]( result: Future[Either[Rejection, T]] )( | |
implicit | |
executionContext: ExecutionContext | |
): Directive1[T] = onSuccess( result ).flatMap( eitherRejection ) | |
def upload( req: HttpRequest ): Future[Either[Rejection,HttpResponse]] = | |
Source.single( Right( req ) ). | |
via( storageClient.upload( uploadFlow ) ). | |
runWith( Sink.head ) | |
val route:Route = path( "upload" ) { | |
( get & authenticateJwt( validator ) ) { userContext ⇒ ctx ⇒ | |
eitherRejectionAsync( upload( ctx.request ) )( executionContext ) { response: HttpResponse ⇒ | |
complete( response ) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aha, thanks! I forgot I could use extractRequest so I figured I'd access it directly. It worked now and thanks for the background as well, it helps a lot.