File tree 2 files changed +11
-10
lines changed
src/main/kotlin/no/java/conf/plugins
2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -7,18 +7,19 @@ import io.ktor.server.response.respondRedirect
7
7
import io.ktor.server.routing.RoutingContext
8
8
import no.java.conf.model.ApiError
9
9
10
- context(RoutingContext )
11
- suspend inline fun <reified A : Any > Either <ApiError , A >.respond (status : HttpStatusCode = HttpStatusCode .OK ) =
10
+ suspend inline fun <reified A : Any > Either <ApiError , A >.respond (
11
+ context : RoutingContext ,
12
+ status : HttpStatusCode = HttpStatusCode .OK
13
+ ) =
12
14
when (this ) {
13
- is Either .Left -> respond(value)
14
- is Either .Right -> call.respond(status, value)
15
+ is Either .Left -> context. respond(value)
16
+ is Either .Right -> context. call.respond(status, value)
15
17
}
16
18
17
19
suspend fun RoutingContext.respond (error : ApiError ) = call.respond(error.statusCode, error.messageMap())
18
20
19
- context(RoutingContext )
20
- suspend inline fun <reified A : Any > Either <ApiError , A >.respondRedirect (url : String ) =
21
+ suspend inline fun <reified A : Any > Either <ApiError , A >.respondRedirect (context : RoutingContext , url : String ) =
21
22
when (this ) {
22
- is Either .Left -> respond(value)
23
- is Either .Right -> call.respondRedirect(url)
23
+ is Either .Left -> context. respond(value)
24
+ is Either .Right -> context. call.respondRedirect(url)
24
25
}
Original file line number Diff line number Diff line change @@ -86,15 +86,15 @@ fun Application.configureSearchRouting(service: SearchService) {
86
86
get(" /videos" ) {
87
87
either {
88
88
service.allVideos()
89
- }.respond()
89
+ }.respond(this )
90
90
}
91
91
92
92
post {
93
93
either {
94
94
service.textSearch(
95
95
runCatching<TextSearchRequest ?> { call.receiveNullable<TextSearchRequest >() }.getOrNull()
96
96
)
97
- }.respond()
97
+ }.respond(this )
98
98
}
99
99
}
100
100
}
You can’t perform that action at this time.
0 commit comments