Skip to content

Commit

Permalink
Fix frontendId qid parse issue
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jan 29, 2023
1 parent 1c0a91f commit 14a24da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion leetcode/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (c *cnClient) GetQuestionData(slug string) (*QuestionData, error) {
}
q := resp.Data.Question
if q.TitleSlug == "" {
return nil, errors.New("question not found")
return nil, ErrQuestionNotFound
}
if q.IsPaidOnly && q.Content == "" {
return nil, ErrPaidOnlyQuestion
Expand Down
12 changes: 7 additions & 5 deletions leetcode/qid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/j178/leetgo/config"
)

var ErrNoQuestion = errors.New("no such question")
var ErrQuestionNotFound = errors.New("no such question")

func QuestionFromCacheBySlug(slug string, c Client) (*QuestionData, error) {
q := GetCache(c).GetBySlug(slug)
if q != nil {
q.client = c
return q, nil
}
return nil, ErrNoQuestion
return nil, ErrQuestionNotFound
}

func QuestionFromCacheByID(id string, c Client) (*QuestionData, error) {
Expand All @@ -27,7 +27,7 @@ func QuestionFromCacheByID(id string, c Client) (*QuestionData, error) {
q.client = c
return q, nil
}
return nil, ErrNoQuestion
return nil, ErrQuestionNotFound
}

// QuestionBySlug loads question data from cache first, if not found, fetch from leetcode.com
Expand Down Expand Up @@ -63,15 +63,17 @@ func ParseQID(qid string, c Client) ([]*QuestionData, error) {
case strings.Contains(qid, "/"):
_, qs, err = ParseContestQID(qid, c, true)
}
if err == ErrNoQuestion {
if err == ErrQuestionNotFound {
err = nil
}
if err != nil {
return nil, fmt.Errorf("invalid qid \"%s\": %w", qid, err)
}
// Try slug as last resort
if q == nil && len(qs) == 0 {
q, err = QuestionBySlug(qid, c)
if err == ErrQuestionNotFound {
q, err = QuestionFromCacheByID(qid, c)
}
if err != nil {
return nil, fmt.Errorf("invalid qid \"%s\": %w", qid, err)
}
Expand Down

0 comments on commit 14a24da

Please sign in to comment.