Skip to content

Instantly share code, notes, and snippets.

@magnusart
Created July 17, 2015 08:24
Show Gist options
  • Save magnusart/a3b9321d6e391889d59a to your computer and use it in GitHub Desktop.
Save magnusart/a3b9321d6e391889d59a to your computer and use it in GitHub Desktop.
Route DSL type errors
[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 ⇒
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 )
}
}
}
@magnusart
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment