Skip to content

Commit 144118b

Browse files
Fizzadarclaude
andcommitted
Retry Reddit edge blocks instead of skipping events
Reddit's edge can return temporary HTML 403s. Beyond 404/410, a 4xx is now only permanent when the Matrix server returns an errcode, and reaction images only fall back to text on 404/410. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 91979f5 commit 144118b

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎pkg/connector/emoji.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var reactionHTTPClient = &http.Client{
4545
Timeout: 30 * time.Second,
4646
CheckRedirect: func(req *http.Request, via []*http.Request) error {
4747
if len(via) >= 3 || req.URL.Scheme != "https" || req.URL.Host != "i.redd.it" {
48-
return unbridgeable(errors.New("unexpected reaction image redirect"))
48+
return errors.New("unexpected reaction image redirect")
4949
}
5050
return nil
5151
},
@@ -72,7 +72,7 @@ func (r *RedditClient) reactionImage(ctx context.Context, key string) (string, s
7272
defer resp.Body.Close()
7373
if resp.StatusCode != http.StatusOK {
7474
err = fmt.Errorf("reddit reaction image is unavailable (HTTP %d)", resp.StatusCode)
75-
if isPermanentStatus(resp.StatusCode) {
75+
if isGoneStatus(resp.StatusCode) {
7676
err = unbridgeable(err)
7777
}
7878
return "", "", err

‎pkg/connector/media.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func mediaError(ctx context.Context, operation string, err error) error {
4747
if errors.As(err, &httpErr) && httpErr.Response != nil {
4848
safe = fmt.Errorf("%s failed (HTTP %d)", operation, httpErr.Response.StatusCode)
4949
}
50-
if isUnbridgeable(err) || isPermanentHTTPError(err) {
50+
if isPermanentHTTPError(err) {
5151
return unbridgeable(safe)
5252
}
5353
return safe

‎pkg/connector/unbridgeable.go‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,20 @@ func isUnbridgeable(err error) bool {
2929
}
3030

3131
// The server refused this specific request, so repeating it cannot succeed.
32-
// Expired sessions, timeouts and rate limits are retried.
32+
// Beyond not-found, require a Matrix errcode: Reddit's edge also returns
33+
// temporary HTML blocks. Expired sessions, timeouts and rate limits retry.
3334
func isPermanentHTTPError(err error) bool {
3435
var httpErr mautrix.HTTPError
35-
return errors.As(err, &httpErr) && httpErr.Response != nil && !isUnauthorized(err) && isPermanentStatus(httpErr.Response.StatusCode)
36+
if !errors.As(err, &httpErr) || httpErr.Response == nil || isUnauthorized(err) {
37+
return false
38+
}
39+
code := httpErr.Response.StatusCode
40+
if isGoneStatus(code) {
41+
return true
42+
}
43+
return httpErr.RespError != nil && code >= 400 && code < 500 && code != http.StatusRequestTimeout && code != http.StatusTooManyRequests
3644
}
3745

38-
func isPermanentStatus(code int) bool {
39-
return code >= 400 && code < 500 && code != http.StatusUnauthorized && code != http.StatusRequestTimeout && code != http.StatusTooManyRequests
46+
func isGoneStatus(code int) bool {
47+
return code == http.StatusNotFound || code == http.StatusGone
4048
}

0 commit comments

Comments
 (0)