mirror of https://github.com/bumi/lntip
Better error logging
This commit is contained in:
parent
b49e118e47
commit
3029a91726
|
@ -52,12 +52,14 @@ func main() {
|
||||||
e.POST("/v1/invoices", func(c echo.Context) error {
|
e.POST("/v1/invoices", func(c echo.Context) error {
|
||||||
i := new(Invoice)
|
i := new(Invoice)
|
||||||
if err := c.Bind(i); err != nil {
|
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)
|
invoice, err := lnClient.AddInvoice(i.Value, i.Memo)
|
||||||
if err != nil {
|
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)
|
return c.JSON(http.StatusOK, invoice)
|
||||||
|
@ -65,7 +67,13 @@ func main() {
|
||||||
|
|
||||||
e.GET("/v1/invoice/:invoiceId", func(c echo.Context) error {
|
e.GET("/v1/invoice/:invoiceId", func(c echo.Context) error {
|
||||||
invoiceId := c.Param("invoiceId")
|
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)
|
return c.JSON(http.StatusOK, invoice)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ type LNDclient struct {
|
||||||
func (c LNDclient) AddInvoice(value int64, memo string) (Invoice, error) {
|
func (c LNDclient) AddInvoice(value int64, memo string) (Invoice, error) {
|
||||||
result := Invoice{}
|
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{
|
invoice := lnrpc.Invoice{
|
||||||
Memo: memo,
|
Memo: memo,
|
||||||
Value: value,
|
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.
|
// An error is returned if no corresponding invoice was found.
|
||||||
func (c LNDclient) GetInvoice(paymentHashStr string) (Invoice, error) {
|
func (c LNDclient) GetInvoice(paymentHashStr string) (Invoice, error) {
|
||||||
var invoice Invoice
|
var invoice Invoice
|
||||||
stdOutLogger.Printf("Lookup invoice: hash=%s\n", paymentHashStr)
|
stdOutLogger.Printf("Getting invoice: hash=%s\n", paymentHashStr)
|
||||||
|
|
||||||
plainHash, err := hex.DecodeString(paymentHashStr)
|
plainHash, err := hex.DecodeString(paymentHashStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue