mirror of
https://git.freesoftwareextremist.com/bloat
synced 2024-12-22 09:10:42 +00:00
Show signin button in case of an auth error
This commit is contained in:
parent
816281c225
commit
7d389d2258
2 changed files with 23 additions and 3 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,8 @@ func (s *service) ErrorPage(c *client, err error, retry bool) error {
|
|||
var sessionErr bool
|
||||
if err != nil {
|
||||
errStr = err.Error()
|
||||
if err == errInvalidSession || err == errInvalidCSRFToken {
|
||||
if me, ok := err.(mastodon.Error); ok && me.IsAuthError() ||
|
||||
err == errInvalidSession || err == errInvalidCSRFToken {
|
||||
sessionErr = true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue