Skip to content

Commit

Permalink
chore: minor event handler improvements
Browse files Browse the repository at this point in the history
- fix error code response when failing to update request event
- fix log content when failing to decrypt request event
- move logging of app to correct place
  • Loading branch information
rolznz committed Oct 29, 2024
1 parent d4c6a60 commit 63c3fd9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions nip47/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ func (svc *nip47Service) HandleEvent(ctx context.Context, relay nostrmodels.Rela
return
}

logger.Logger.WithFields(logrus.Fields{
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
"appId": app.ID,
}).Debug("App found for nostr event")

appWalletPrivKey := svc.keys.GetNostrSecretKey()

if app.WalletPubkey != nil {
Expand Down Expand Up @@ -113,7 +119,7 @@ func (svc *nip47Service) HandleEvent(ctx context.Context, relay nostrmodels.Rela

nip47Response = &models.Response{
Error: &models.Error{
Code: constants.ERROR_UNAUTHORIZED,
Code: constants.ERROR_INTERNAL,
Message: fmt.Sprintf("Failed to save app to nostr event: %s", err.Error()),
},
}
Expand All @@ -137,12 +143,6 @@ func (svc *nip47Service) HandleEvent(ctx context.Context, relay nostrmodels.Rela
return
}

logger.Logger.WithFields(logrus.Fields{
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
"appId": app.ID,
}).Debug("App found for nostr event")

payload, err := nip04.Decrypt(event.Content, ss)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
Expand All @@ -153,7 +153,7 @@ func (svc *nip47Service) HandleEvent(ctx context.Context, relay nostrmodels.Rela
logger.Logger.WithFields(logrus.Fields{
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
}).WithError(err).Error("Failed to process event")
}).WithError(err).Error("Failed to decrypt request event")

requestEvent.State = db.REQUEST_EVENT_STATE_HANDLER_ERROR
err = svc.db.Save(&requestEvent).Error
Expand Down

0 comments on commit 63c3fd9

Please sign in to comment.