File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
mirai-api-http/src/main/kotlin/net/mamoe/mirai/api/http/adapter/http Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,22 @@ package net.mamoe.mirai.api.http.adapter.http.plugin
12
12
import io.ktor.server.application.*
13
13
import io.ktor.server.application.hooks.*
14
14
import io.ktor.server.response.*
15
+ import io.ktor.util.*
15
16
import net.mamoe.mirai.api.http.adapter.internal.handler.toStateCode
16
17
17
- val GlobalExceptionHandler = createApplicationPlugin(" GlobalExceptionHandler" ) {
18
+ val GlobalExceptionHandler = createApplicationPlugin(
19
+ " GlobalExceptionHandler" ,
20
+ ::GlobalExceptionHandlerConfig
21
+ ) {
18
22
on(CallFailed ) { call, cause ->
23
+ if (pluginConfig.printTrace) {
24
+ cause.printStackTrace()
25
+ }
19
26
call.respond(cause.toStateCode())
20
27
}
28
+ }
29
+
30
+ @KtorDsl
31
+ class GlobalExceptionHandlerConfig {
32
+ var printTrace: Boolean = false
21
33
}
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ fun Application.httpModule(adapter: HttpAdapter) {
35
35
}
36
36
37
37
install(ContentNegotiation ) { json(json = BuiltinJsonSerializer .buildJson()) }
38
- install(GlobalExceptionHandler )
38
+ install(GlobalExceptionHandler ) { printTrace = MahContextHolder .debug }
39
39
install(Authorization )
40
40
if (MahContextHolder .debug) {
41
41
install(DoubleReceive )
You can’t perform that action at this time.
0 commit comments