Skip to content

Instantly share code, notes, and snippets.

@freeone3000
Created February 19, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freeone3000/69611dcb8ca9417382cbb13e788233eb to your computer and use it in GitHub Desktop.
Save freeone3000/69611dcb8ca9417382cbb13e788233eb to your computer and use it in GitHub Desktop.
private suspend fun ApplicationCall.respondStoryWith(sessionFactory: SessionFactory) {
try {
findStoryStream(parameters["id"]!!, sessionFactory).use { stream ->
respondBytes(io.ktor.http.ContentType.parse("application/x-zmachine"), io.ktor.http.HttpStatusCode.OK) {
stream.readAllBytes() //TODO ???
}
}
} catch(ex: UnsupportedOperationException) {
respond(io.ktor.http.HttpStatusCode.NotFound, ex.message ?: "Resource not found")
} catch(ex: IllegalArgumentException) {
respond(io.ktor.http.HttpStatusCode.BadRequest, ex.message ?: "Invalid target name")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment