I got the following runtime exception. But I can’t see where Predef$.require is used in Handshake.
Any tips?
java.lang.IllegalArgumentException: requirement failed: Tried to choose invalid subprotocol ‘Some(json)’ which wasn’t offered by the client: []
at scala.Predef$.require(Predef.scala:337)
at akka.http.impl.engine.ws.Handshake$Server$$anon$1.handle(Handshake.scala:120)
at akka.http.impl.engine.ws.Handshake$Server$$anon$1.handleMessages(Handshake.scala:128)
at $mycode
where $mycode contains
val upgrade: WebSocketUpgrade = ???
val selectedProtocol: String = ???
upgrade..handleMessages(
Flow.fromSinkAndSourceCoupled(sink, source),
Some(selectedProtocol)
)
The file hasn’t changed in many years beyond copyright headers, so that’s current.
The functions and values in Predef are implicitly imported into every Scala file. In this case, require is validating that, if a subProtocol is specified ("json" in this case), it’s one of the protocols sent by the client in the Sec-WebSocket-Protocol header; in this case the client sent no protocols in that header.