From 3b7ac31615b9901e0c020e3ca639e2d31795f902 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sun, 24 Oct 2021 11:32:00 +0200 Subject: [PATCH] Better error logging for the LNURL endpoint This checks for errors when creating the invoice and logs the error and returns an LNURL error response. Before it would return a blank pr. --- lnme.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lnme.go b/lnme.go index 8608d13..5056753 100644 --- a/lnme.go +++ b/lnme.go @@ -164,11 +164,16 @@ func main() { stdOutLogger.Printf("New LightningAddress request amount: %s", amount) msats, err := strconv.ParseInt(amount, 10, 64) if err != nil || msats < 1000 { + stdOutLogger.Printf("Invalid amount: %s", amount) return c.JSON(http.StatusOK, lnurl.LNURLErrorResponse{Status: "ERROR", Reason: "Invalid Amount"}) } sats := msats / 1000 // we need sats metadataHash := sha256.Sum256([]byte(lnurlMetadata)) invoice, err := lnClient.AddInvoice(sats, lightningAddress, metadataHash[:]) + if err != nil { + stdOutLogger.Printf("Error creating invoice: %s", err) + return c.JSON(http.StatusOK, lnurl.LNURLErrorResponse{Status: "ERROR", Reason: "Server Error"}) + } lnurlPayResponse2 := lnurl.LNURLPayResponse2{ LNURLResponse: lnurl.LNURLResponse{Status: "OK"}, PR: invoice.PaymentRequest,