From 651f3683d27642b706d120f9292c4c1e9612dca5 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Sat, 24 Jul 2021 06:02:47 +0100 Subject: [PATCH] feat: handle tweets from suspended accounts --- main.go | 17 ++++++++++++++++- suspendedTweet.svg | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 suspendedTweet.svg diff --git a/main.go b/main.go index 46457e2..ff8ea68 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "github.com/joho/godotenv" ) -//go:embed index.html tweet.svg.tmpl +//go:embed index.html tweet.svg.tmpl suspendedTweet.svg var content embed.FS @@ -77,6 +77,15 @@ func getTweet(w http.ResponseWriter, r *http.Request) { } tweet, err := api.GetTweet(i, nil) if err != nil { + switch err := err.(type) { + case *anaconda.ApiError: + switch err.Decoded.Errors[0].Code { + case 63: + fmt.Printf("Generating suspended tweet image for %s\n", id) + suspendedTweet(w) + return + } + } w.WriteHeader(404) return } @@ -192,3 +201,9 @@ func getTweet(w http.ResponseWriter, r *http.Request) { return } } + +func suspendedTweet(w http.ResponseWriter) { + w.Header().Set("Content-type", "image/svg+xml") + tweet, _ := content.ReadFile("suspendedTweet.svg") + w.Write(tweet) +} diff --git a/suspendedTweet.svg b/suspendedTweet.svg new file mode 100644 index 0000000..70d249e --- /dev/null +++ b/suspendedTweet.svg @@ -0,0 +1 @@ +This Tweet is from a suspended account.