From 3029a9172641ec4ebe5e97b5362a06ca56e52962 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Thu, 21 Feb 2019 02:13:31 +0100 Subject: [PATCH] Better error logging --- invoices_proxy.go | 14 +++++++++++--- ln/lnd.go | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/invoices_proxy.go b/invoices_proxy.go index da06b00..d52e264 100644 --- a/invoices_proxy.go +++ b/invoices_proxy.go @@ -52,12 +52,14 @@ func main() { e.POST("/v1/invoices", func(c echo.Context) error { i := new(Invoice) if err := c.Bind(i); err != nil { - return c.JSON(http.StatusBadRequest, "bad request") + stdOutLogger.Printf("Bad request: %s", err) + return c.JSON(http.StatusBadRequest, "Bad request") } invoice, err := lnClient.AddInvoice(i.Value, i.Memo) if err != nil { - return c.JSON(http.StatusInternalServerError, "invoice creation error") + stdOutLogger.Printf("Error creating invoice: %s", err) + return c.JSON(http.StatusInternalServerError, "Error adding invoice") } return c.JSON(http.StatusOK, invoice) @@ -65,7 +67,13 @@ func main() { e.GET("/v1/invoice/:invoiceId", func(c echo.Context) error { invoiceId := c.Param("invoiceId") - invoice, _ := lnClient.GetInvoice(invoiceId) + invoice, err := lnClient.GetInvoice(invoiceId) + + if err != nil { + stdOutLogger.Printf("Error looking up invoice: %s", err) + return c.JSON(http.StatusInternalServerError, "Error fetching invoice") + } + return c.JSON(http.StatusOK, invoice) }) diff --git a/ln/lnd.go b/ln/lnd.go index e9db571..82e8656 100644 --- a/ln/lnd.go +++ b/ln/lnd.go @@ -35,7 +35,7 @@ type LNDclient struct { func (c LNDclient) AddInvoice(value int64, memo string) (Invoice, error) { result := Invoice{} - stdOutLogger.Printf("Creating invoice: memo=%s amount=%v ", memo, value) + stdOutLogger.Printf("Adding invoice: memo=%s amount=%v ", memo, value) invoice := lnrpc.Invoice{ Memo: memo, Value: value, @@ -54,7 +54,7 @@ func (c LNDclient) AddInvoice(value int64, memo string) (Invoice, error) { // An error is returned if no corresponding invoice was found. func (c LNDclient) GetInvoice(paymentHashStr string) (Invoice, error) { var invoice Invoice - stdOutLogger.Printf("Lookup invoice: hash=%s\n", paymentHashStr) + stdOutLogger.Printf("Getting invoice: hash=%s\n", paymentHashStr) plainHash, err := hex.DecodeString(paymentHashStr) if err != nil {