lnd icon indicating copy to clipboard operation
lnd copied to clipboard

REST API returns a 500 Internal Server Error when trying to fetch an invoice if there are no invoices at all

Open thomaseizinger opened this issue 5 years ago • 1 comments

Background

I am using the REST API to retrieve the state of an invoice:

curl --cacert $LND_DIR/tls.cert --header "$MACAROON_HEADER" 'https://localhost:8080/v1/invoice/014fe7c24f2c5723cf0dfc16c68b996462f8a081b4cdc8a21e93ab4abd8f9f6c'

Your environment

  • version of lnd: lnd version 0.9.0-beta commit=v0.9.0-beta-rc1

  • which operating system (uname -a on *Nix): Linux thomas-ThinkPad-T480 4.15.0-91-generic #92-Ubuntu SMP Fri Feb 28 11:09:48 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

  • version of btcd, bitcoind, or other backend: irrelevant for this issue

Steps to reproduce

  • Start up a new instance of lnd
  • Make up an invoice hash
  • Try to request it through the REST API

Expected behaviour

The API should return a 404, signaling that the invoice does not exist.

Actual behaviour

Lnd returns a 500 Internal Server Error:

HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Trailer: Grpc-Trailer-Content-Type
Date: Tue, 31 Mar 2020 23:58:42 GMT
Transfer-Encoding: chunked

{
    "error": "there are no existing invoices",
    "message": "there are no existing invoices",
    "code": 2
}

According to the HTTP spec, status code 500 is to be used for:

The server encountered an unexpected condition which prevented it from fulfilling the request.

I would argue that a non-existent invoice is certainly not unexpected and hence status code 500 is inappropriate here.

thomaseizinger avatar Mar 31 '20 23:03 thomaseizinger

Possibly related to https://github.com/lightningnetwork/lnd/issues/2332.

wpaulino avatar Apr 01 '20 16:04 wpaulino