diff --git a/backend/internal/controller/http/v1/assets.go b/backend/internal/controller/http/v1/assets.go index a100b88c..d3045046 100644 --- a/backend/internal/controller/http/v1/assets.go +++ b/backend/internal/controller/http/v1/assets.go @@ -97,7 +97,7 @@ type UpdateAuthFlagsRequest struct { func (r *assetsRoutes) createAsset(c *gin.Context) { var request CreateAssetRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } @@ -108,19 +108,19 @@ func (r *assetsRoutes) createAsset(c *gin.Context) { sponsor, err := r.w.Get(sponsorID) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } res, err := r.m.SendMessage(entity.CreateKeypairChannel, entity.CreateKeypairRequest{Amount: 2}) if err != nil { - errorResponse(c, http.StatusInternalServerError, "kms messaging problems") + errorResponse(c, http.StatusInternalServerError, "kms messaging problems", err) return } kpRes, ok := res.Message.(entity.CreateKeypairResponse) if !ok || len(kpRes.PublicKeys) != 2 { - errorResponse(c, http.StatusInternalServerError, "unexpected kms response") + errorResponse(c, http.StatusInternalServerError, "unexpected kms response", err) return } issuerPk := kpRes.PublicKeys[0] @@ -186,12 +186,12 @@ func (r *assetsRoutes) createAsset(c *gin.Context) { Operations: ops, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok = res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -218,7 +218,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) { } asset, err = r.as.Create(asset) if err != nil { - errorResponse(c, http.StatusNotFound, "database problems") + errorResponse(c, http.StatusNotFound, "database problems", err) return } @@ -239,7 +239,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) { func (r *assetsRoutes) mintAsset(c *gin.Context) { var request MintAssetRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } @@ -249,13 +249,13 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) { } _, err := r.w.Get(request.SponsorId) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } asset, err := r.as.GetById(request.Id) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } ops := []entity.Operation{ @@ -275,15 +275,14 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) { PublicKeys: []string{asset.Issuer.Key.PublicKey}, Operations: ops, }) - if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok := res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -304,13 +303,13 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) { func (r *assetsRoutes) burnAsset(c *gin.Context) { var request BurnAssetRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } asset, err := r.as.GetById(request.Id) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } @@ -320,7 +319,7 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) { } _, err = r.w.Get(request.SponsorId) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } ops := []entity.Operation{ @@ -342,13 +341,13 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) { Operations: ops, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok := res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -371,13 +370,13 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) { func (r *assetsRoutes) transferAsset(c *gin.Context) { var request TransferAssetRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } sourceWallet, err := r.w.Get(request.SourceWalletID) if err != nil { - errorResponse(c, http.StatusNotFound, "source wallet not found") + errorResponse(c, http.StatusNotFound, "source wallet not found", err) return } @@ -387,13 +386,13 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) { } _, err = r.w.Get(request.SponsorId) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } asset, err := r.as.GetById(request.AssetID) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } ops := []entity.Operation{ @@ -415,13 +414,13 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) { Operations: ops, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok := res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -442,7 +441,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) { func (r *assetsRoutes) clawbackAsset(c *gin.Context) { var request ClawbackAssetRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } @@ -452,13 +451,13 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) { } sponsor, err := r.w.Get(request.SponsorId) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } asset, err := r.as.Get(request.Code) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } @@ -482,13 +481,13 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) { Operations: ops, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok := res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -509,13 +508,13 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) { func (r *assetsRoutes) updateAuthFlags(c *gin.Context) { var request UpdateAuthFlagsRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } asset, err := r.as.Get(request.Code) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } @@ -523,7 +522,7 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) { if request.TrustorId != 0 { trustor, err = r.w.Get(request.TrustorId) if err != nil { - errorResponse(c, http.StatusNotFound, "trustor wallet not found") + errorResponse(c, http.StatusNotFound, "trustor wallet not found", err) return } } else if request.TrustorPK != "" { @@ -544,7 +543,7 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) { sponsor, err := r.w.Get(_sponsorId) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } @@ -554,13 +553,13 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) { Operations: []entity.Operation{op}, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok := res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -578,7 +577,7 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) { func (r *assetsRoutes) getAllAssets(c *gin.Context) { assets, err := r.as.GetAll() if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting assets") + errorResponse(c, http.StatusInternalServerError, "error getting assets", err) return } @@ -597,7 +596,7 @@ func (r *assetsRoutes) getAssetById(c *gin.Context) { assetId := c.Param("id") assets, err := r.as.GetById(assetId) if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting asset") + errorResponse(c, http.StatusInternalServerError, "error getting asset", err) return } diff --git a/backend/internal/controller/http/v1/contracts.go b/backend/internal/controller/http/v1/contracts.go index 29e59c12..1ef5a5fa 100644 --- a/backend/internal/controller/http/v1/contracts.go +++ b/backend/internal/controller/http/v1/contracts.go @@ -19,7 +19,8 @@ type contractRoutes struct { } func newContractRoutes(handler *gin.RouterGroup, m HTTPControllerMessenger, a usecase.AuthUseCase, c usecase.ContractUseCase, v usecase.VaultUseCase, - as usecase.AssetUseCase) { + as usecase.AssetUseCase, +) { r := &contractRoutes{m, a, c, v, as} h := handler.Group("/contract").Use(Auth(r.a.ValidateToken())) { @@ -56,25 +57,25 @@ func (r *contractRoutes) createContract(c *gin.Context) { var err error if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } asset, err := r.as.GetById(request.AssetId) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } vaultId, err := strconv.Atoi(request.VaultId) if err != nil { - errorResponse(c, http.StatusBadRequest, "invalid vault ID") + errorResponse(c, http.StatusBadRequest, "invalid vault ID", err) return } vault, err := r.v.GetById(vaultId) if err != nil { - errorResponse(c, http.StatusNotFound, "vault not found") + errorResponse(c, http.StatusNotFound, "vault not found", err) return } @@ -91,7 +92,7 @@ func (r *contractRoutes) createContract(c *gin.Context) { contract, err = r.c.Create(contract) if err != nil { - errorResponse(c, http.StatusNotFound, fmt.Sprintf("error: %s", err.Error())) + errorResponse(c, http.StatusNotFound, fmt.Sprintf("error: %s", err.Error()), err) return } @@ -109,7 +110,7 @@ func (r *contractRoutes) createContract(c *gin.Context) { func (r *contractRoutes) getAllContracts(c *gin.Context) { contract, err := r.v.GetAll() if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting contract") + errorResponse(c, http.StatusInternalServerError, "error getting contract", err) return } @@ -129,12 +130,12 @@ func (r *contractRoutes) getContractById(c *gin.Context) { vaultId, err := strconv.Atoi(idStr) if err != nil { - errorResponse(c, http.StatusBadRequest, "invalid vault ID") + errorResponse(c, http.StatusBadRequest, "invalid vault ID", err) return } contract, err := r.v.GetById(vaultId) if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting contract") + errorResponse(c, http.StatusInternalServerError, "error getting contract", err) return } diff --git a/backend/internal/controller/http/v1/error.go b/backend/internal/controller/http/v1/error.go index 506b4159..f0db75ba 100644 --- a/backend/internal/controller/http/v1/error.go +++ b/backend/internal/controller/http/v1/error.go @@ -8,6 +8,9 @@ type response struct { Error string `json:"error" example:"message"` } -func errorResponse(c *gin.Context, code int, msg string) { - c.AbortWithStatusJSON(code, response{msg}) +func errorResponse(c *gin.Context, code int, msg string, err error) { + c.AbortWithStatusJSON(code, gin.H{ + "message": msg, + "error": err, + }) } diff --git a/backend/internal/controller/http/v1/role.go b/backend/internal/controller/http/v1/role.go index 2e474301..57ca9d02 100644 --- a/backend/internal/controller/http/v1/role.go +++ b/backend/internal/controller/http/v1/role.go @@ -33,7 +33,7 @@ func newRoleRoutes(handler *gin.RouterGroup, roleUseCase usecase.RoleUseCase, me func (r *role) list(c *gin.Context) { roles, err := r.roleUseCase.List() if err != nil { - errorResponse(c, http.StatusInternalServerError, "database problems") + errorResponse(c, http.StatusInternalServerError, "database problems", err) } c.JSON(http.StatusOK, roles) } diff --git a/backend/internal/controller/http/v1/role_permissions.go b/backend/internal/controller/http/v1/role_permissions.go index 88c5cd07..4bcbf181 100644 --- a/backend/internal/controller/http/v1/role_permissions.go +++ b/backend/internal/controller/http/v1/role_permissions.go @@ -33,7 +33,7 @@ func (r *rolePermissions) rolePermissions(c *gin.Context) { token := c.GetHeader("Authorization") rolePermissions, err := r.rolePermissionUseCase.GetRolePermissions(token) if err != nil { - errorResponse(c, http.StatusInternalServerError, "database problems") + errorResponse(c, http.StatusInternalServerError, "database problems", err) } c.JSON(http.StatusOK, rolePermissions) } diff --git a/backend/internal/controller/http/v1/users.go b/backend/internal/controller/http/v1/users.go index f77d6898..9e99aaca 100644 --- a/backend/internal/controller/http/v1/users.go +++ b/backend/internal/controller/http/v1/users.go @@ -107,7 +107,7 @@ func (r *usersRoutes) autentication(c *gin.Context) { var user entity.User if err := c.ShouldBindJSON(&user); err != nil { // r.l.Error(err, "http - v1 - create") - errorResponse(c, http.StatusBadRequest, "invalid request body") + errorResponse(c, http.StatusBadRequest, "invalid request body", err) fmt.Println(err) return } @@ -115,7 +115,7 @@ func (r *usersRoutes) autentication(c *gin.Context) { user, err := r.t.Autentication(user.Email, user.Password) if err != nil { // r.l.Error(err, "http - v1 - create") - errorResponse(c, http.StatusInternalServerError, "database problems") + errorResponse(c, http.StatusInternalServerError, "database problems", err) fmt.Println(err) return } diff --git a/backend/internal/controller/http/v1/utils.go b/backend/internal/controller/http/v1/utils.go index 9c867c5a..ff102150 100644 --- a/backend/internal/controller/http/v1/utils.go +++ b/backend/internal/controller/http/v1/utils.go @@ -36,18 +36,18 @@ func (m *HTTPControllerMessenger) SendMessage(chanName string, value interface{} res := <-channel notify.Stop(msgKey, channel) - if notifyData, ok := res.(*entity.NotifyData); ok { - switch msg := notifyData.Message.(type) { - case entity.EnvelopeResponse: - if msg.StatusCode != 200 { - return nil, fmt.Errorf("sendMessage - error response: %v", msg) - } - return notifyData, nil + // if notifyData, ok := res.(*entity.NotifyData); ok { + // switch msg := notifyData.Message.(type) { + // case entity.EnvelopeResponse: + // if msg.StatusCode != 200 { + // return nil, fmt.Errorf("sendMessage - error response: %v", msg) + // } + // return notifyData, nil - default: - return notifyData, nil - } - } + // default: + // return notifyData, nil + // } + // } return res.(*entity.NotifyData), nil } diff --git a/backend/internal/controller/http/v1/vault.go b/backend/internal/controller/http/v1/vault.go index 13fe5cad..46df7cd1 100644 --- a/backend/internal/controller/http/v1/vault.go +++ b/backend/internal/controller/http/v1/vault.go @@ -68,13 +68,13 @@ func (r *vaultRoutes) createVault(c *gin.Context) { var err error if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } vaultCategory, err := r.vc.GetById(request.VaultCategoryId) if err != nil { - errorResponse(c, http.StatusNotFound, "source wallet not found") + errorResponse(c, http.StatusNotFound, "source wallet not found", err) return } @@ -82,19 +82,19 @@ func (r *vaultRoutes) createVault(c *gin.Context) { sponsor, err := r.w.Get(sponsorID) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } res, err := r.m.SendMessage(entity.CreateKeypairChannel, entity.CreateKeypairRequest{Amount: 1}) if err != nil { - errorResponse(c, http.StatusInternalServerError, "kms messaging problems") + errorResponse(c, http.StatusInternalServerError, "kms messaging problems", err) return } kpRes, ok := res.Message.(entity.CreateKeypairResponse) if !ok || len(kpRes.PublicKeys) != 1 { - errorResponse(c, http.StatusInternalServerError, "unexpected kms response") + errorResponse(c, http.StatusInternalServerError, "unexpected kms response", err) return } walletPk := kpRes.PublicKeys[0] @@ -112,7 +112,7 @@ func (r *vaultRoutes) createVault(c *gin.Context) { for _, assetId := range request.AssetsId { asset, err := r.as.GetById(strconv.Itoa(assetId)) if err != nil { - errorResponse(c, http.StatusNotFound, "asset not found") + errorResponse(c, http.StatusNotFound, "asset not found", err) return } @@ -133,12 +133,12 @@ func (r *vaultRoutes) createVault(c *gin.Context) { Operations: ops, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok = res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -159,7 +159,7 @@ func (r *vaultRoutes) createVault(c *gin.Context) { vault, err = r.v.Create(vault) if err != nil { - errorResponse(c, http.StatusNotFound, fmt.Sprintf("error: %s", err.Error())) + errorResponse(c, http.StatusNotFound, fmt.Sprintf("error: %s", err.Error()), err) return } @@ -177,7 +177,7 @@ func (r *vaultRoutes) createVault(c *gin.Context) { func (r *vaultRoutes) getAllVaults(c *gin.Context) { vault, err := r.v.GetAll() if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting vault") + errorResponse(c, http.StatusInternalServerError, "error getting vault", err) return } @@ -196,13 +196,13 @@ func (r *vaultRoutes) getVaultById(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) if err != nil { - errorResponse(c, http.StatusBadRequest, "invalid vault ID") + errorResponse(c, http.StatusBadRequest, "invalid vault ID", err) return } vault, err := r.v.GetById(id) if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting vault") + errorResponse(c, http.StatusInternalServerError, "error getting vault", err) return } @@ -226,13 +226,13 @@ func (r *vaultRoutes) updateVaultCategory(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) if err != nil { - errorResponse(c, http.StatusBadRequest, "invalid vault ID") + errorResponse(c, http.StatusBadRequest, "invalid vault ID", err) return } var request UpdateVaultCategoryRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } @@ -240,10 +240,10 @@ func (r *vaultRoutes) updateVaultCategory(c *gin.Context) { existingVault, err := r.v.GetById(id) if err != nil { if err.Error() == "VaultRepo - GetVaultById - Vault not found" { - errorResponse(c, http.StatusNotFound, "vault not found") + errorResponse(c, http.StatusNotFound, "vault not found", err) return } - errorResponse(c, http.StatusInternalServerError, "error finding vault") + errorResponse(c, http.StatusInternalServerError, "error finding vault", err) return } @@ -253,7 +253,7 @@ func (r *vaultRoutes) updateVaultCategory(c *gin.Context) { updatedVault, err := r.v.UpdateVault(existingVault) if err != nil { - errorResponse(c, http.StatusInternalServerError, "error updating vault category") + errorResponse(c, http.StatusInternalServerError, "error updating vault category", err) return } @@ -277,26 +277,26 @@ func (r *vaultRoutes) updateVaultAsset(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) if err != nil { - errorResponse(c, http.StatusBadRequest, "invalid vault ID") + errorResponse(c, http.StatusBadRequest, "invalid vault ID", err) return } var request []UpdateVaultAssetRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } // Get the vault by its ID and the asset by its ID vault, err := r.v.GetById(id) if err != nil { - errorResponse(c, http.StatusNotFound, "vault not found") + errorResponse(c, http.StatusNotFound, "vault not found", err) return } sponsor, err := r.w.Get(_sponsorId) if err != nil { - errorResponse(c, http.StatusNotFound, "sponsor wallet not found") + errorResponse(c, http.StatusNotFound, "sponsor wallet not found", err) return } @@ -335,13 +335,13 @@ func (r *vaultRoutes) updateVaultAsset(c *gin.Context) { Operations: ops, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems") + errorResponse(c, http.StatusInternalServerError, "starlabs messaging problems", err) return } _, ok := res.Message.(entity.EnvelopeResponse) if !ok { - errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response") + errorResponse(c, http.StatusInternalServerError, "unexpected starlabs response", err) return } @@ -364,7 +364,7 @@ func (r *vaultRoutes) deleteVault(c *gin.Context) { idStr := c.Param("id") id, err := strconv.Atoi(idStr) if err != nil { - errorResponse(c, http.StatusBadRequest, "invalid vault ID") + errorResponse(c, http.StatusBadRequest, "invalid vault ID", err) return } @@ -372,10 +372,10 @@ func (r *vaultRoutes) deleteVault(c *gin.Context) { existingVault, err := r.v.GetById(id) if err != nil { if err.Error() == "VaultRepo - GetVaultById - Vault not found" { - errorResponse(c, http.StatusNotFound, "vault not found") + errorResponse(c, http.StatusNotFound, "vault not found", err) return } - errorResponse(c, http.StatusInternalServerError, "error finding vault") + errorResponse(c, http.StatusInternalServerError, "error finding vault", err) return } @@ -384,7 +384,7 @@ func (r *vaultRoutes) deleteVault(c *gin.Context) { deletedVault, err := r.v.DeleteVault(existingVault) if err != nil { - errorResponse(c, http.StatusInternalServerError, "error delete vault") + errorResponse(c, http.StatusInternalServerError, "error delete vault", err) return } diff --git a/backend/internal/controller/http/v1/vault_category.go b/backend/internal/controller/http/v1/vault_category.go index b7b1c276..9cc51491 100644 --- a/backend/internal/controller/http/v1/vault_category.go +++ b/backend/internal/controller/http/v1/vault_category.go @@ -45,7 +45,7 @@ func (r *vaultCategoryRoutes) createVaultCategory(c *gin.Context) { var err error if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error())) + errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid request body: %s", err.Error()), err) return } @@ -56,7 +56,7 @@ func (r *vaultCategoryRoutes) createVaultCategory(c *gin.Context) { vaultCategory, err = r.vc.Create(vaultCategory) if err != nil { - errorResponse(c, http.StatusNotFound, "database problems") + errorResponse(c, http.StatusNotFound, "database problems", err) return } @@ -74,7 +74,7 @@ func (r *vaultCategoryRoutes) createVaultCategory(c *gin.Context) { func (r *vaultCategoryRoutes) getAllVaultCategories(c *gin.Context) { vaultCategories, err := r.vc.GetAll() if err != nil { - errorResponse(c, http.StatusInternalServerError, "error getting vault categories") + errorResponse(c, http.StatusInternalServerError, "error getting vault categories", err) return } diff --git a/backend/internal/controller/http/v1/wallets.go b/backend/internal/controller/http/v1/wallets.go index f4fa1a81..156be433 100644 --- a/backend/internal/controller/http/v1/wallets.go +++ b/backend/internal/controller/http/v1/wallets.go @@ -38,7 +38,7 @@ func (r *walletsRoutes) list(c *gin.Context) { wallets, err := r.w.List(walletType) if err != nil { - errorResponse(c, http.StatusInternalServerError, "database problems") + errorResponse(c, http.StatusInternalServerError, "database problems", err) } c.JSON(http.StatusOK, wallets) @@ -61,13 +61,13 @@ type CreateWalletRequest struct { func (r *walletsRoutes) create(c *gin.Context) { var request CreateWalletRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, "invalid request body") + errorResponse(c, http.StatusBadRequest, "invalid request body", err) return } res, err := r.m.SendMessage(entity.CreateKeypairChannel, entity.CreateKeypairRequest{Amount: 1}) if err != nil { - errorResponse(c, http.StatusInternalServerError, "messaging problems") + errorResponse(c, http.StatusInternalServerError, "messaging problems", err) return } @@ -82,7 +82,7 @@ func (r *walletsRoutes) create(c *gin.Context) { }, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "database problems") + errorResponse(c, http.StatusInternalServerError, "database problems", err) return } @@ -107,19 +107,19 @@ type FundWalletRequest struct { func (r *walletsRoutes) fundWallet(c *gin.Context) { var request FundWalletRequest if err := c.ShouldBindJSON(&request); err != nil { - errorResponse(c, http.StatusBadRequest, "invalid request body: %x") + errorResponse(c, http.StatusBadRequest, "invalid request body: %x", err) return } wallet, err := r.w.Get(request.Id) if err != nil { fmt.Println(err) - errorResponse(c, http.StatusNotFound, "wallet not found") + errorResponse(c, http.StatusNotFound, "wallet not found", err) return } if wallet.Funded { - errorResponse(c, http.StatusBadRequest, "wallet is already funded") + errorResponse(c, http.StatusBadRequest, "wallet is already funded", err) return } @@ -129,13 +129,13 @@ func (r *walletsRoutes) fundWallet(c *gin.Context) { Account: wallet.Key.PublicKey, }) if err != nil { - errorResponse(c, http.StatusInternalServerError, "messaging problems") + errorResponse(c, http.StatusInternalServerError, "messaging problems", err) } fundRes := res.Message.(entity.HorizonResponse) if fundRes.StatusCode != 200 { - errorResponse(c, http.StatusInternalServerError, "friendbot error") + errorResponse(c, http.StatusInternalServerError, "friendbot error", err) return } @@ -143,7 +143,7 @@ func (r *walletsRoutes) fundWallet(c *gin.Context) { wallet, err = r.w.Update(wallet) if err != nil { fmt.Println(err) - errorResponse(c, http.StatusInternalServerError, "database problems") + errorResponse(c, http.StatusInternalServerError, "database problems", err) return }