diff --git a/nip47/controllers/lookup_invoice_controller.go b/nip47/controllers/lookup_invoice_controller.go index 85f1847e..e6f862ac 100644 --- a/nip47/controllers/lookup_invoice_controller.go +++ b/nip47/controllers/lookup_invoice_controller.go @@ -2,11 +2,13 @@ package controllers import ( "context" + "errors" "fmt" "strings" "github.com/getAlby/hub/logger" "github.com/getAlby/hub/nip47/models" + "github.com/getAlby/hub/transactions" "github.com/nbd-wtf/go-nostr" decodepay "github.com/nbd-wtf/ln-decodepay" "github.com/sirupsen/logrus" @@ -72,10 +74,15 @@ func (controller *nip47Controller) HandleLookupInvoiceEvent(ctx context.Context, "payment_hash": paymentHash, }).Infof("Failed to lookup invoice: %v", err) + code := models.ERROR_INTERNAL + if errors.Is(err, transactions.NewNotFoundError()) { + code = models.ERROR_NOT_FOUND + } + publishResponse(&models.Response{ ResultType: nip47Request.Method, Error: &models.Error{ - Code: models.ERROR_INTERNAL, + Code: code, Message: err.Error(), }, }, nostr.Tags{}) diff --git a/nip47/models/models.go b/nip47/models/models.go index 34f8ef79..f89380f0 100644 --- a/nip47/models/models.go +++ b/nip47/models/models.go @@ -30,6 +30,7 @@ const ( ERROR_EXPIRED = "EXPIRED" ERROR_RESTRICTED = "RESTRICTED" ERROR_BAD_REQUEST = "BAD_REQUEST" + ERROR_NOT_FOUND = "NOT_FOUND" OTHER = "OTHER" ) diff --git a/transactions/transactions_service.go b/transactions/transactions_service.go index 2bbf6a30..e01af20c 100644 --- a/transactions/transactions_service.go +++ b/transactions/transactions_service.go @@ -32,6 +32,17 @@ type TransactionsService interface { type Transaction = db.Transaction +type notFoundError struct { +} + +func NewNotFoundError() error { + return ¬FoundError{} +} + +func (err *notFoundError) Error() string { + return "Not Found" +} + const ( TRANSACTION_TYPE_INCOMING = "incoming" TRANSACTION_TYPE_OUTGOING = "outgoing" @@ -290,7 +301,7 @@ func (svc *transactionsService) LookupTransaction(ctx context.Context, paymentHa } if result.RowsAffected == 0 { - return nil, errors.New("transaction not found") + return nil, NewNotFoundError() } if transaction.State == TRANSACTION_STATE_PENDING {