From f3251e78e587297963c3b5d2892048c8e3eca99e Mon Sep 17 00:00:00 2001 From: pm47 Date: Mon, 25 Mar 2024 15:44:44 +0100 Subject: [PATCH] explicit message in case of 4XX failures ``` $ curl -u :bad-password http://127.0.0.1:9740/getinfo Invalid authentication (use basic auth with the http password set in phoenix.conf) $ curl -u :4034..8232 http://127.0.0.1:9740/getinfowithtypo Unknown endpoint (check api doc) $ curl -u :4034..8232 -X POST http://127.0.0.1:9740/getinfowithtypo Invalid http method (use the correct GET/POST) ``` --- src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt index 41d9f1f..1a1e510 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt @@ -64,6 +64,15 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va exception { call, cause -> call.respondText(text = cause.message ?: "", status = defaultExceptionStatusCode(cause) ?: HttpStatusCode.InternalServerError) } + status(HttpStatusCode.Unauthorized) { call, status -> + call.respondText(text = "Invalid authentication (use basic auth with the http password set in phoenix.conf)", status = status) + } + status(HttpStatusCode.MethodNotAllowed) { call, status -> + call.respondText(text = "Invalid http method (use the correct GET/POST)", status = status) + } + status(HttpStatusCode.NotFound) { call, status -> + call.respondText(text = "Unknown endpoint (check api doc)", status = status) + } } install(Authentication) { basic {