Skip to content

Commit 95abfd2

Browse files
committed
Add exceptionDetailsConfiguration parameter to lpfcpServer and lpfcp route
1 parent 4a7572e commit 95abfd2

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
`ktor` module:
88
- Updated Ktor to version `3.1.3`
99
- `Ktor.LPFCPServer` now holds the entire embedded server instead of `NettyApplicationEngine`
10-
- Added `eraseStackTraces` param to `lpfcpServer` and `lpfcp` route.
11-
When it is set — all stack traces are automatically erased from responses to a client.
12-
This will help to hide internal server implementations from users.
10+
- Added `exceptionDetailsConfiguration` parameter to `lpfcpServer` and `lpfcp` route.
11+
It allows specifying the details to be included in response when the exception is thrown.
12+
This will help to hide internal server implementations from users if needed.
1313
### Other
1414
- Updated dependencies' versions
1515

ktor/src/main/java/eth/likespro/lpfcp/ktor/Ktor.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package eth.likespro.lpfcp.ktor
1010

11+
import eth.likespro.commons.models.WrappedException
1112
import eth.likespro.commons.reflection.ObjectEncoding.encodeObject
1213
import eth.likespro.lpfcp.LPFCP.ExposedFunction
1314
import eth.likespro.lpfcp.LPFCP.processRequest
@@ -48,10 +49,12 @@ object Ktor {
4849
*
4950
* @param processor The object containing the functions to be invoked with [ExposedFunction] annotation.
5051
* @param port The port on which the server will listen to (default is `8080`).
52+
* @param exceptionDetailsConfiguration The configuration for the exception details to be included in the response
53+
* (default is [WrappedException.DetailsConfiguration.INCLUDE_ALL]).
5154
*/
52-
fun lpfcpServer(processor: Any, port: Int = 8080, eraseStackTraces: Boolean = false) = LPFCPServer(embeddedServer(Netty, port) {
55+
fun lpfcpServer(processor: Any, port: Int = 8080, exceptionDetailsConfiguration: WrappedException.DetailsConfiguration = WrappedException.DetailsConfiguration.INCLUDE_ALL) = LPFCPServer(embeddedServer(Netty, port) {
5356
routing {
54-
lpfcp(processor, eraseStackTraces = eraseStackTraces)
57+
lpfcp(processor, exceptionDetailsConfiguration = exceptionDetailsConfiguration)
5558
}
5659
})
5760

@@ -60,13 +63,15 @@ object Ktor {
6063
*
6164
* @param processor The object containing the functions to be invoked with [ExposedFunction] annotation.
6265
* @param path The path for the LPFCP endpoint (default is "/lpfcp").
66+
* @param exceptionDetailsConfiguration The configuration for the exception details to be included in the response
67+
* (default is [WrappedException.DetailsConfiguration.INCLUDE_ALL]).
6368
*/
64-
fun Route.lpfcp(processor: Any, path: String = "/lpfcp", eraseStackTraces: Boolean = false) {
69+
fun Route.lpfcp(processor: Any, path: String = "/lpfcp", exceptionDetailsConfiguration: WrappedException.DetailsConfiguration = WrappedException.DetailsConfiguration.INCLUDE_ALL) {
6570
post(path) {
6671
val request = JSONObject(call.receiveText())
67-
call.respond(processRequest(request, processor).apply {
68-
if(eraseStackTraces) eraseStackTrace()
69-
}.encodeObject())
72+
call.respond(processRequest(request, processor)
73+
.applyExceptionDetailsConfiguration(exceptionDetailsConfiguration)
74+
.encodeObject())
7075
}
7176
}
7277
}

0 commit comments

Comments
 (0)