Skip to content

Commit

Permalink
feat(SPV-848): adjust to new ExtendedError approach
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain committed Jul 9, 2024
1 parent 11bfd7a commit d2b4af7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actions/admin/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package admin
import (
"net/http"

"github.com/bitcoin-sv/spv-wallet/engine/spverrors"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/gin-gonic/gin"
)
Expand All @@ -26,7 +27,7 @@ func (a *Action) subscribeWebhook(c *gin.Context) {

err := a.Services.SpvWalletEngine.SubscribeWebhook(c.Request.Context(), requestBody.URL, requestBody.TokenHeader, requestBody.TokenValue)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
spverrors.ErrorResponse(c, spverrors.ErrWebhookSubscriptionFailed, a.Services.Logger)
return
}

Expand All @@ -52,7 +53,7 @@ func (a *Action) unsubscribeWebhook(c *gin.Context) {

err := a.Services.SpvWalletEngine.UnsubscribeWebhook(c.Request.Context(), requestModel.URL)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
spverrors.ErrorResponse(c, spverrors.ErrWebhookUnsubscriptionFailed, a.Services.Logger)
return
}

Expand Down
8 changes: 8 additions & 0 deletions engine/spverrors/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,11 @@ var ErrMissingClient = models.SPVError{Message: "client is missing from model, c

// ErrDatastoreRequired is when a datastore function is called without a datastore present
var ErrDatastoreRequired = models.SPVError{Message: "datastore is required", StatusCode: 500, Code: "error-datastore-required"}

//////////////////////////////////// NOTIFICATION ERRORS

// ErrWebhookSubscriptionFailed is when webhook subscription failed
var ErrWebhookSubscriptionFailed = models.SPVError{Message: "webhook subscription failed", StatusCode: 500, Code: "error-webhook-subscription-failed"}

// ErrWebhookUnsubscriptionFailed is when webhook unsubscription failed
var ErrWebhookUnsubscriptionFailed = models.SPVError{Message: "webhook unsubscription failed", StatusCode: 500, Code: "error-webhook-unsubscription-failed"}

0 comments on commit d2b4af7

Please sign in to comment.