Play framework Enumerator.outputStream, what if an exception is thrown

I am testing the following code in the 2.4 framework:

def error = Action {
  val enumerator = Enumerator.outputStream { os =>
    // some operations that...
    throw new Exception()
  }
  Ok.stream(enumerator >>> Enumerator.eof).withHeaders(
    CONTENT_TYPE -> "text/plain"
  )
}

When outputStreaman exception is thrown in the function passed to , the enumerator passed in Ok.streamalways hangs. How to fix it?

+4
source share

Source: https://habr.com/ru/post/1609300/


All Articles