From c8faaf4fb54c04306d8b8ddd2068368069db7e86 Mon Sep 17 00:00:00 2001 From: Artem Skriabin Date: Fri, 5 Apr 2024 14:27:34 +0300 Subject: [PATCH] Check user is not nil before getting Provider Data --- internal/service/api/handlers/get_provider_by_identity_id.go | 2 +- internal/service/core/handlers.go | 4 ++++ internal/service/core/identity_providers/models.go | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/service/api/handlers/get_provider_by_identity_id.go b/internal/service/api/handlers/get_provider_by_identity_id.go index 11a56ff..e1e44f7 100644 --- a/internal/service/api/handlers/get_provider_by_identity_id.go +++ b/internal/service/api/handlers/get_provider_by_identity_id.go @@ -21,7 +21,7 @@ func GetProviderByIdentityId(w http.ResponseWriter, r *http.Request) { provider, err := KYCService(r).GetProviderByIdentityId(req) switch { - case errors.Is(err, identityproviders.ErrProviderNotFound): + case errors.Is(err, identityproviders.ErrProviderNotFound), errors.Is(err, identityproviders.ErrUserNotFound): Log(r).WithField("reason", err).Debug("Not found") ape.RenderErr(w, problems.NotFound()) return diff --git a/internal/service/core/handlers.go b/internal/service/core/handlers.go index 11d52c7..27b67d2 100644 --- a/internal/service/core/handlers.go +++ b/internal/service/core/handlers.go @@ -155,6 +155,10 @@ func (k *kycService) GetProviderByIdentityId(req *requests.GetProviderByIdentity return "", errors.Wrap(err, "failed to get user from db with provided identityID") } + if user == nil { + return "", identityproviders.ErrUserNotFound + } + domainData := unstopdom.Domain{} if err := json.Unmarshal(user.ProviderData, &domainData); err != nil { return "", errors.Wrap(err, "failed to unmarshal json") diff --git a/internal/service/core/identity_providers/models.go b/internal/service/core/identity_providers/models.go index 0dc3ffb..6df2f7a 100644 --- a/internal/service/core/identity_providers/models.go +++ b/internal/service/core/identity_providers/models.go @@ -13,6 +13,7 @@ var ( // Not found errors ErrProviderNotFound = errors.New("provider not found") + ErrUserNotFound = errors.New("user not found") ) type IdentityProviderName string