aboutsummaryrefslogtreecommitdiff
path: root/mastodon
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2021-10-23 13:41:41 +0000
committerr <r@freesoftwareextremist.com>2021-10-23 13:41:41 +0000
commit7d389d22581cc785005a42d655eb7f9c32aac3ec (patch)
treef705a2ff549429953b46dc31ed12b695385e44c2 /mastodon
parent816281c225e1d07602aa4f6d87d5ffbbc8dfbb7a (diff)
downloadbloat-7d389d22581cc785005a42d655eb7f9c32aac3ec.tar.gz
bloat-7d389d22581cc785005a42d655eb7f9c32aac3ec.zip
Show signin button in case of an auth error
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/helper.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/mastodon/helper.go b/mastodon/helper.go
index 05af20f..cb0013d 100644
--- a/mastodon/helper.go
+++ b/mastodon/helper.go
@@ -3,12 +3,28 @@ package mastodon
import (
"encoding/base64"
"encoding/json"
- "errors"
"fmt"
"net/http"
"os"
)
+type Error struct {
+ code int
+ err string
+}
+
+func (e Error) Error() string {
+ return e.err
+}
+
+func (e Error) IsAuthError() bool {
+ switch e.code {
+ case http.StatusForbidden, http.StatusUnauthorized:
+ return true
+ }
+ return false
+}
+
// Base64EncodeFileName returns the base64 data URI format string of the file with the file name.
func Base64EncodeFileName(filename string) (string, error) {
file, err := os.Open(filename)
@@ -51,5 +67,8 @@ func parseAPIError(prefix string, resp *http.Response) error {
errMsg = fmt.Sprintf("%s: %s", errMsg, e.Error)
}
- return errors.New(errMsg)
+ return Error{
+ code: resp.StatusCode,
+ err: errMsg,
+ }
}