gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 03/07: helper


From: gnunet
Subject: [libeufin] 03/07: helper
Date: Wed, 12 Apr 2023 11:28:21 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

commit 3f9689f21443af123fb1ac01fab4fba47d7b2eb5
Author: MS <ms@taler.net>
AuthorDate: Wed Apr 12 11:08:26 2023 +0200

    helper
---
 util/src/main/kotlin/HTTP.kt | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt
index d9ff4491..30a15bd9 100644
--- a/util/src/main/kotlin/HTTP.kt
+++ b/util/src/main/kotlin/HTTP.kt
@@ -9,6 +9,7 @@ import io.ktor.server.util.*
 import io.ktor.util.*
 import logger
 import java.net.URLDecoder
+import kotlin.reflect.typeOf
 
 fun unauthorized(msg: String): UtilError {
     return UtilError(
@@ -208,4 +209,14 @@ fun expectLong(uriParam: String): Long {
         logger.error(e.message)
         throw badRequest("'$uriParam' is not Long")
     }
+}
+
+// Returns null, or tries to convert the parameter to type T.
+// Throws Bad Request, if the conversion could not be done.
+fun ApplicationCall.maybeLong(uriParamName: String): Long? {
+    val maybeParam = this.parameters[uriParamName] ?: return null
+    return try { maybeParam.toLong() }
+    catch (e: Exception) {
+        throw badRequest("Could not convert '$uriParamName' to Long")
+    }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]