aboutsummaryrefslogtreecommitdiff
path: root/manga/request_handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'manga/request_handler.go')
-rw-r--r--manga/request_handler.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/manga/request_handler.go b/manga/request_handler.go
index 892289b..8484a57 100644
--- a/manga/request_handler.go
+++ b/manga/request_handler.go
@@ -17,13 +17,16 @@
package manga
import (
- "io/ioutil"
- "log"
- "net/http"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "encoding/json"
+ "github.com/MikunoNaka/MAL2Go/util"
+ "errors"
)
// Handles HTTP request with your OAuth token as a Header
-func (c Client) requestHandler(endpoint string) string {
+func (c Client) requestHandler(endpoint string) (string, error) {
// generate request
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
@@ -44,5 +47,12 @@ func (c Client) requestHandler(endpoint string) string {
log.Fatal(err)
}
- return string(body)
+ // error handling (if API returns error)
+ var errMsg util.APIError
+ json.Unmarshal(body, &errMsg)
+ if errMsg.Err != "" {
+ return string(body), errors.New(errMsg.Err + " " + errMsg.Msg)
+ }
+
+ return string(body), nil
}