88
99package eth.likespro.lpfcp.ktor
1010
11+ import eth.likespro.commons.models.WrappedException
1112import eth.likespro.commons.reflection.ObjectEncoding.encodeObject
1213import eth.likespro.lpfcp.LPFCP.ExposedFunction
1314import 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