Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

fix: return error nil get response restrict user #351

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package goinsta
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -115,7 +116,10 @@ func (insta *Instagram) sendRequest(o *reqOptions) (body []byte, err error) {
body, err = ioutil.ReadAll(resp.Body)
if err == nil {
err = isError(resp.StatusCode, body)
} else if resp.StatusCode == http.StatusBadRequest {
err = isError(resp.StatusCode, body)
}

return body, err
}

Expand All @@ -136,6 +140,8 @@ func isError(code int, body []byte) (err error) {
if ierr.Message == "challenge_required" {
return ierr.ChallengeError

} else if ierr.Message == "feedback_required" {
return errors.New("fail: " + ierr.FeedbackMessage)
}

if err == nil && ierr.Message != "" {
Expand Down
7 changes: 4 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func (e ErrorN) Error() string {
// Error400 is error returned by HTTP 400 status code.
type Error400 struct {
ChallengeError
Action string `json:"action"`
StatusCode string `json:"status_code"`
Payload struct {
FeedbackMessage string `json:"feedback_message"`
Action string `json:"action"`
StatusCode string `json:"status_code"`
Payload struct {
ClientContext string `json:"client_context"`
Message string `json:"message"`
} `json:"payload"`
Expand Down