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

Commit 6f9dfaf

Browse files
authored
Merge pull request #32 from LF-Engineering/fix-profile-by-username-bug
Fix index out of range if user not found
2 parents 5c9eb15 + 08a8a8c commit 6f9dfaf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

affiliation/identity.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package affiliation
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"log"
78
"net/url"
@@ -294,12 +295,16 @@ func (a *Affiliation) GetProfileByUsername(username string, projectSlug string)
294295
headers := make(map[string]string, 0)
295296
headers["Authorization"] = fmt.Sprintf("%s %s", "Bearer", token)
296297
endpoint := a.AffBaseURL + "/affiliation/" + url.PathEscape(projectSlug) + "/get_profile_by_username/" + url.PathEscape(username)
297-
_, res, err := a.httpClient.Request(strings.TrimSpace(endpoint), "GET", headers, nil, nil)
298+
statusCode, res, err := a.httpClient.Request(strings.TrimSpace(endpoint), "GET", headers, nil, nil)
298299
if err != nil {
299300
log.Println("GetProfileByUsername: Could not get the profile: ", err)
300301
return nil, err
301302
}
302303

304+
if statusCode != 200 {
305+
return nil, errors.New("User not found")
306+
}
307+
303308
var profile UniqueIdentityFullProfile
304309
err = json.Unmarshal(res, &profile)
305310
if err != nil {

0 commit comments

Comments
 (0)