[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.
- [libeufin] branch master updated (1b9fbb02 -> bcf54117), gnunet, 2023/04/12
- [libeufin] 02/07: testing DB events, gnunet, 2023/04/12
- [libeufin] 01/07: Helpers., gnunet, 2023/04/12
- [libeufin] 04/07: comments, indentation., gnunet, 2023/04/12
- [libeufin] 07/07: comment, gnunet, 2023/04/12
- [libeufin] 05/07: DB events., gnunet, 2023/04/12
- [libeufin] 03/07: helper,
gnunet <=
- [libeufin] 06/07: DB events at Access API., gnunet, 2023/04/12