mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-23 15:44:51 +01:00
capture errors
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/getAlby/lndhub.go/db/models"
|
"github.com/getAlby/lndhub.go/db/models"
|
||||||
|
"github.com/getsentry/sentry-go"
|
||||||
amqp "github.com/rabbitmq/amqp091-go"
|
amqp "github.com/rabbitmq/amqp091-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -65,27 +66,33 @@ func (svc *LndhubService) StartRabbitMqPublisher(ctx context.Context) error {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return context.Canceled
|
return context.Canceled
|
||||||
case incoming := <-incomingInvoices:
|
case incoming := <-incomingInvoices:
|
||||||
svc.publishInvoice(ctx, incoming, ch)
|
err = svc.publishInvoice(ctx, incoming, ch)
|
||||||
|
if err != nil {
|
||||||
|
svc.Logger.Error(err)
|
||||||
|
sentry.CaptureException(err)
|
||||||
|
}
|
||||||
case outgoing := <-outgoingInvoices:
|
case outgoing := <-outgoingInvoices:
|
||||||
svc.publishInvoice(ctx, outgoing, ch)
|
err = svc.publishInvoice(ctx, outgoing, ch)
|
||||||
|
if err != nil {
|
||||||
|
svc.Logger.Error(err)
|
||||||
|
sentry.CaptureException(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *LndhubService) publishInvoice(ctx context.Context, invoice models.Invoice, ch *amqp.Channel) {
|
func (svc *LndhubService) publishInvoice(ctx context.Context, invoice models.Invoice, ch *amqp.Channel) error {
|
||||||
key := fmt.Sprintf("invoice.%s.%s", invoice.Type, invoice.State)
|
key := fmt.Sprintf("invoice.%s.%s", invoice.Type, invoice.State)
|
||||||
|
|
||||||
user, err := svc.FindUser(context.Background(), invoice.UserID)
|
user, err := svc.FindUser(context.Background(), invoice.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
svc.Logger.Error(err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := bufPool.Get().(*bytes.Buffer)
|
payload := bufPool.Get().(*bytes.Buffer)
|
||||||
err = json.NewEncoder(payload).Encode(convertPayload(invoice, user))
|
err = json.NewEncoder(payload).Encode(convertPayload(invoice, user))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
svc.Logger.Error(err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ch.PublishWithContext(ctx,
|
err = ch.PublishWithContext(ctx,
|
||||||
@@ -99,8 +106,8 @@ func (svc *LndhubService) publishInvoice(ctx context.Context, invoice models.Inv
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
svc.Logger.Error(err)
|
return err
|
||||||
return
|
|
||||||
}
|
}
|
||||||
svc.Logger.Debugf("Succesfully published invoice to rabbitmq with RHash %s", invoice.RHash)
|
svc.Logger.Debugf("Succesfully published invoice to rabbitmq with RHash %s", invoice.RHash)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user