ACINQ / phoenixd

https://phoenix.acinq.co/server
Apache License 2.0
117 stars 15 forks source link

/payinvoice and /sendtoaddress return HTTP 200 status code when erroring #42

Open coyotte508 opened 7 months ago

coyotte508 commented 7 months ago

For example:

curl -v -X 'POST' 'http://localhost:9740/sendtoaddress' \
  -u :phoenixd_api_password \
  -d 'amountSat=100000' \
  -d 'address=invalid_address' \
  -d 'feerateSatByte=12'

I get this error:

* Connected to localhost (127.0.0.1) port 9740 (#0)
* Server auth using Basic with user ''
> POST /sendtoaddress HTTP/1.1
> Host: localhost:9740
> Authorization: Basic ...
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Length: 58
> Content-Type: application/x-www-form-urlencoded
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 15
< Content-Type: text/plain; charset=UTF-8
< 
* Connection #0 to host localhost left intact
invalid address%   

I get a 200 error code instead of a 400 (or 422)

For the /payinvoice endpoint, same thing.

Code change

https://github.com/ACINQ/phoenixd/blob/18035566f8b7b89bac2bfbb40071506e0fc69c1c/src/commonMain/kotlin/fr/acinq/lightning/bin/Api.kt#L171 , add , status = ... probably in the respondText?

Workarounds