Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit b3ed531

Browse files
authored
Merge pull request #65 from LF-Engineering/handle-getidentity-notfound-error
Fix get identity not found error handling
2 parents 964d468 + 8c27a6e commit b3ed531

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

affiliation/identity.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"log"
8-
httpNative "net/http"
8+
"net/http"
99
"net/url"
1010
"strings"
1111
"time"
@@ -95,7 +95,7 @@ func (a *Affiliation) AddIdentity(identity *Identity) bool {
9595

9696
endpoint := a.AffBaseURL + "/affiliation/" + url.PathEscape(a.ProjectSlug) + "/add_identity/" + url.PathEscape(identity.Source)
9797
statusCode, res, err := a.httpClientProvider.Request(strings.TrimSpace(endpoint), "POST", headers, nil, queryParams)
98-
if statusCode != httpNative.StatusOK {
98+
if statusCode != http.StatusOK {
9999
if err != nil {
100100
log.Println("AddIdentity: Could not insert the identity: ", err)
101101
}
@@ -216,11 +216,14 @@ func (a *Affiliation) GetIdentityByUser(key string, value string) (*AffIdentity,
216216
endpoint := a.AffBaseURL + "/affiliation/" + "identity/" + key + "/" + value
217217
statusCode, res, err := a.httpClientProvider.Request(strings.TrimSpace(endpoint), "GET", headers, nil, nil)
218218
switch statusCode {
219-
case httpNative.StatusOK, httpNative.StatusNotFound:
220-
219+
case http.StatusBadRequest, http.StatusNotFound:
220+
log.Println("GetIdentityByUser: Could not get the identity: l", err)
221+
return &AffIdentity{}, errors.New("identity not found")
222+
case http.StatusOK:
221223
default:
222224
if err != nil {
223225
log.Println("GetIdentityByUser: Could not get the identity: ", err)
226+
return &AffIdentity{}, err
224227
}
225228

226229
var errMsg AffiliationsResponse
@@ -236,14 +239,16 @@ func (a *Affiliation) GetIdentityByUser(key string, value string) (*AffIdentity,
236239
var ident IdentityData
237240
err = json.Unmarshal(res, &ident)
238241
if err != nil {
239-
return nil, err
242+
return &AffIdentity{}, err
240243
}
241244

242245
profileEndpoint := a.AffBaseURL + "/affiliation/" + url.PathEscape(a.ProjectSlug) + "/get_profile/" + *ident.UUID
243246
statusCode, profileRes, err := a.httpClientProvider.Request(strings.TrimSpace(profileEndpoint), "GET", headers, nil, nil)
244247
switch statusCode {
245-
case httpNative.StatusOK, httpNative.StatusNotFound:
246-
248+
case http.StatusBadRequest,http.StatusNotFound :
249+
log.Println("GetIdentityByUser: Could not get the identity: ", err)
250+
return &AffIdentity{}, errors.New("identity not found")
251+
case http.StatusOK:
247252
default:
248253
if err != nil {
249254
log.Println("GetIdentityByUser: Could not get the identity: ", err)

0 commit comments

Comments
 (0)