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)

```
This commit is contained in:
pm47 2024-03-25 15:44:44 +01:00
parent df91b9604f
commit f3251e78e5
No known key found for this signature in database
GPG Key ID: E434ED292E85643A

View File

@ -64,6 +64,15 @@ class Api(private val nodeParams: NodeParams, private val peer: Peer, private va
exception<Throwable> { 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 {