mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Remove AccessError error struct
This commit is contained in:
parent
7db4ca6b93
commit
5e3636015b
2 changed files with 2 additions and 30 deletions
|
|
@ -248,21 +248,14 @@ func (c *Crunchyroll) request(endpoint string) (*http.Response, error) {
|
||||||
bodyAsBytes, _ := io.ReadAll(resp.Body)
|
bodyAsBytes, _ := io.ReadAll(resp.Body)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode == http.StatusUnauthorized {
|
if resp.StatusCode == http.StatusUnauthorized {
|
||||||
return nil, &AccessError{
|
return nil, fmt.Errorf("invalid access token")
|
||||||
URL: endpoint,
|
|
||||||
Body: bodyAsBytes,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var errStruct struct {
|
var errStruct struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
json.NewDecoder(bytes.NewBuffer(bodyAsBytes)).Decode(&errStruct)
|
json.NewDecoder(bytes.NewBuffer(bodyAsBytes)).Decode(&errStruct)
|
||||||
if errStruct.Message != "" {
|
if errStruct.Message != "" {
|
||||||
return nil, &AccessError{
|
return nil, fmt.Errorf(errStruct.Message)
|
||||||
URL: endpoint,
|
|
||||||
Body: bodyAsBytes,
|
|
||||||
Message: errStruct.Message,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.Body = io.NopCloser(bytes.NewBuffer(bodyAsBytes))
|
resp.Body = io.NopCloser(bytes.NewBuffer(bodyAsBytes))
|
||||||
|
|
|
||||||
21
error.go
21
error.go
|
|
@ -1,21 +0,0 @@
|
||||||
package crunchyroll
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// AccessError is an error which will be returned when some special sort of api request fails.
|
|
||||||
// See Crunchyroll.request when the error gets used.
|
|
||||||
type AccessError struct {
|
|
||||||
error
|
|
||||||
|
|
||||||
URL string
|
|
||||||
Body []byte
|
|
||||||
Message string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ae *AccessError) Error() string {
|
|
||||||
if ae.Message == "" {
|
|
||||||
return fmt.Sprintf("Access token invalid for url %s\nBody: %s", ae.URL, string(ae.Body))
|
|
||||||
} else {
|
|
||||||
return ae.Message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue