Skip to content

Commit

Permalink
fix(fetch): handle case for badges with null value for expiration
Browse files Browse the repository at this point in the history
some badges do not have expiry dates therefore API response contains a null value, nested if should handle by adding a zero value for the expected data type
  • Loading branch information
shanilhirani committed Aug 9, 2024
1 parent 1ed12d6 commit 62f5f5e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ func FilterData(username string, data *types.CredlyData, includeExpired bool) ([
// Parse the ExpiresAtDate string into a time.Time value
expiresAtDate, err := parseExpiresAtDate(badge.ExpiresAtDate)
if err != nil {
return nil, fmt.Errorf("failed to parse ExpiresAtDate for badge ID %s: %v", badge.ID, err)
if badge.ExpiresAtDate == "" {
// Handle the case where ExpiresAtDate is an empty string (null)
expiresAtDate = time.Time{} // Set a zero value for time.Time
} else {
return nil, fmt.Errorf("failed to parse ExpiresAtDate for badge ID %s: %v", badge.ID, err)
}

Check warning on line 117 in internal/fetch/fetch.go

View check run for this annotation

Codecov / codecov/patch

internal/fetch/fetch.go#L110-L117

Added lines #L110 - L117 were not covered by tests
}

// Check if the badge is expired or if we want to include expired badges
Expand Down

0 comments on commit 62f5f5e

Please sign in to comment.