by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Konrad `ktoso` Malawski
    @ktoso
    Spray is end of life since quite a long time, you won’t get too much active feedback; I’d recommend upgrading to Akka HTTP (very similar API, should be simple)
    the concept you want to read up about is rejections in general and rejection handlers
    my above comment still stands though ;)
    Conor
    @somethingconcon
    @ktoso :D thanks for the info! Planning on upgrading within the month as part of our next milestone. I have my rejection handler setup correctly (I think) but in the code I can’t find how to deal with it. Any suggestions would be very helpful.
    codedef rejection(implicit logging: LoggingContext) =
    RejectionHandler {
    case Nil => ctx =>
    respondToBadRequest(ctx, "The requested resource could not be found.")
      case MalformedQueryParamRejection(param, message, error) :: _ => ctx =>
        respondToBadRequest(ctx, s"Malformed params: $param")
    
      case MissingQueryParamRejection(param) :: _ => ctx =>
        respondToBadRequest(ctx, s"Missing params: $param")
    
      case MissingFormFieldRejection(field) :: _ => ctx =>
        respondToBadRequest(ctx, s"Missing field $field")
    
      case MalformedFormFieldRejection(field, error, cause) :: _ => ctx =>
        respondToBadRequest(ctx, s"Malformed field $field. Error: $error")
    
      case MalformedRequestContentRejection(message, cause) :: _ => ctx =>
        respondToBadRequest(ctx, message)
    
      case RequestEntityExpectedRejection :: _ => ctx => {
        val message =
          s"""Request entity expected but not supplied.
              | Target: ${ctx.request.unmatchedPath}
              | Entity: ${ctx.request.entity.asString}
          """
    
        respondToBadRequest(ctx, message)
      }
    
      case SchemeRejection(message) :: _  => ctx =>
        respondToBadRequest(ctx, s"Schema rejection. Error: $message")
    
      case MethodRejection(message) :: _ => ctx =>
        respondToRejection(ctx, s"Method not allowed on this resource. Error $message", MethodNotAllowed)
    
      case UnsupportedRequestContentTypeRejection(error) :: _ => ctx =>
        respondToBadRequest(ctx, error)
    
      case ValidationRejection(message, cause) :: _ => ctx =>
        respondToBadRequest(ctx, s"Validation rejection: $message")
    }
    oh, poo
    Konrad `ktoso` Malawski
    @ktoso
    sorry too much code for me go to over now, getting late here
    Conor
    @somethingconcon
    now worries, cheers :D
    s/now/no
    Konrad `ktoso` Malawski
    @ktoso
    basically handle the rejection, and return exactly what you want
    we have docs for this in akka http
    google things around “akka http rejection handler json"
    Conor
    @somethingconcon
    @ktoso oh one more question. Is akka-http planning on adopting play-json in the near future or is spray-json here to stay?
    Konrad `ktoso` Malawski
    @ktoso
    there’s no need to “adopt”; it just works ™ with play-json
    Conor
    @somethingconcon
    noice!
    :D :D :D
    Konrad `ktoso` Malawski
    @ktoso
    noice indeed ;)
    lemonxah
    @lemonxah
    hi guys
    Error:(52, 15) Cannot find JsonWriter or JsonFormat type class for List[com.konga.order.models.Order]
    it does this for all list types
    and i do have
    import com.konga.order.models.OrderJsonSupport._
    import DefaultJsonProtocol._
    Arnout Engelen
    @raboof
    @lemonxah have you verified it works for com.konga.order.models.Order when it's not in a List?
    lemonxah
    @lemonxah
    nvm found the issue .. the OrderJsonSupport extended DefaultJsonProtocol as well removed that and it works
    Arnout Engelen
    @raboof
    ah yes if you have multiple matching implicits the compiler sometimes makes it look like none matched, very confusing indeed
    lemonxah
    @lemonxah
    normally i would have ambigious implicit
    but now .. nothing matched .. that was very confusing
    Abhiraj Padhye
    @A4Abhiraj
    Hey everyone! This issue is still open. Can anyone help ?
    spray/spray-json#159
    Andrey Ivanov
    @a-nigredo

    Hi all, I am busy with migration from spray to akka-http and don't understand what happens with such a code:

    def route = path(Segment) {
     actorReffactory.actorOf("")
    }

    What will be in a response then?

    How spray process actorRef as a response?
    Konrad `ktoso` Malawski
    @ktoso
    this won’t compile
    please ask on gitter.im/akka/akka btw :)
    it won’t compile, exactly because the question you ask can’t be answered statically — akka http enforces these things
    Andrey Ivanov
    @a-nigredo
    @ktoso I know that it is not compiled in akka-http but in spray. My question is what convertion spray uses to handle such case?
    Jameel Al-Aziz
    @jalaziz
    Curious if this is a known thing before I open up a ticket. RouteTest in the testkit appears to eagerly create and start the actor system. While this normally wouldn't be an issue, we use ScalaTest's tagging to include/exclude tests. The eager loading slows things down considerably as the actor system will be initialized even though no tests are actually run.
    Konrad `ktoso` Malawski
    @ktoso
    Spray has been end of life since a few years, please migrate do akka-http (migration is usually rather simple), and ask there then
    Jameel Al-Aziz
    @jalaziz
    ahh, good point, forgot about that, we actually do use akka-http for newer things
    thanks!
    although, looks like it's still eager in akka-http, but will upgrade first
    Konrad `ktoso` Malawski
    @ktoso
    yeap, upgrade and ask on https://discuss.akka.io I propose :) happy hakking
    ShankarShastri
    @shankarshastri
    Is there a way to parse a JSON like this in spray?
    {
    "k1": [
    "k2": { "k3" : 1 },
    "k4": {"k41" : 2}
    ]
    }
    Kirill Yankov
    @manonthegithub

    @shankarshastri you can use spray-json.

    import spray.json._
    val jsonString: String = ???
    
    val json: JsObject = jsonString.parseJson.asJsObject

    or you can declare a class describing this json and declare format for it and then convert to it directly:

    
    class JsonRepr(???)
    
    implicit object ReprFormat extends RootJsonFormat[JsonRepr]{
       ???
    }
    
    import spray.json._
    val jsonString: String = ???
    jsonString.parseJson.convertTo[ReprFormat]
    ShankarShastri
    @shankarshastri
    But I don't know the key names @manonthegithub
    to specify them in case class
    Kirill Yankov
    @manonthegithub
    then probably the first sample val json: JsObject = jsonString.parseJson.asJsObject is your option
    you can then get Map[String, JsValue] of the fields of the JsObject
    jsonString.parseJson.asJsObject.fields will return Map[String, JsValue]
    ShankarShastri
    @shankarshastri
    I wanted to understand spray json library.
    Any hints to tell where to start from?
    I meant code.
    Vladislav Rybin
    @VladislavRybin
    hey guys, does anyone else have false error highlights in spray routes when using IntelliJ IDEA?
    All my code is covered in red highlighting :^)
    Is there a way to fix this?