~netlandish/links

dc68fa3bcd2f0f5c4ae39eeaca63165152714257 — Peter Sanchez 5 days ago 5851060
Add a bot check to avoid annoying error emails.
1 files changed, 14 insertions(+), 3 deletions(-)

M client.go
M client.go => client.go +14 -3
@@ 4,6 4,7 @@ import (
	"context"
	"fmt"
	"net/http"
	"strings"
	"time"

	"git.sr.ht/~emersion/gqlclient"


@@ 80,9 81,19 @@ func Execute(ctx context.Context, op *gqlclient.Operation, result interface{}) e

	client = gqlclient.New(origin, httpClient)
	err := client.Execute(ctx, op, &result)
	if graphErrors, ok := err.(interface{ Unwrap() []error }); ok {
		errs := graphErrors.Unwrap()
		err = errs[0]
	if err != nil {
		if graphErrors, ok := err.(interface{ Unwrap() []error }); ok {
			errs := graphErrors.Unwrap()
			err = errs[0]
		} else {
			estr := err.Error()
			if strings.HasPrefix(estr, "HTTP request failed:") &&
				strings.HasSuffix(estr, "context canceled") {
				// Stupid f'n bots. Return this because gobwebs will not send an error email
				// for this error
				return context.Canceled
			}
		}
	}
	return err
}

Do not follow this link