~netlandish/links-dev

links: Add a bot check to avoid annoying error emails. v1 APPLIED

Peter Sanchez: 1
 Add a bot check to avoid annoying error emails.

 1 files changed, 14 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.code.netlandish.com/~netlandish/links-dev/patches/111/mbox | git am -3
Learn more about email & git

[PATCH links] Add a bot check to avoid annoying error emails. Export this patch

---
 client.go | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/client.go b/client.go
index ed5e7e2..3bc6a68 100644
--- a/client.go
+++ b/client.go
@@ -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
}
-- 
2.47.2
Applied.

To git@git.code.netlandish.com:~netlandish/links
   5851060..dc68fa3  master -> master