Skip to content

Commit

Permalink
Add diff to InvalidChallengeTsError
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjcochran committed Aug 19, 2019
1 parent cf966bb commit 2975381
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func ChallengeTs(window time.Duration) Criterion {
if diff := now().Sub(r.ChallengeTs); diff > window {
return &InvalidChallengeTsError{
ChallengeTs: r.ChallengeTs,
Diff: diff,
}
}
return nil
Expand Down
1 change: 1 addition & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ func TestVerify(t *testing.T) {
},
expected: &InvalidChallengeTsError{
ChallengeTs: now().Add(-time.Second),
Diff: time.Second,
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ func (e *InvalidScoreError) Error() string {
// window.
type InvalidChallengeTsError struct {
ChallengeTs time.Time
Diff time.Duration
}

func (e *InvalidChallengeTsError) Error() string {
return fmt.Sprintf("invalid reCAPTCHA: invalid challenge timestamp: %s", e.ChallengeTs)
return fmt.Sprintf("invalid reCAPTCHA: invalid challenge timestamp: %s (%s old)", e.ChallengeTs, e.Diff)
}

0 comments on commit 2975381

Please # to comment.