Skip to content
This repository was archived by the owner on Aug 25, 2021. It is now read-only.
12 changes: 12 additions & 0 deletions anticaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package anticaptcha
import (
"bytes"
"encoding/json"
"github.com/pkg/errors"
"log"
"net/http"
"net/url"
"time"
"reflect"
)

var (
Expand Down Expand Up @@ -47,6 +49,9 @@ func (c *Client) createTaskRecaptcha(websiteURL string, recaptchaKey string) (fl
responseBody := make(map[string]interface{})
json.NewDecoder(resp.Body).Decode(&responseBody)
// TODO treat api errors and handle them properly
if reflect.ValueOf(responseBody["taskId"]).IsNil() {
return "", errors.Errorf("Failed to get a response")
}
return responseBody["taskId"].(float64), nil
}

Expand Down Expand Up @@ -104,6 +109,10 @@ func (c *Client) SendRecaptcha(websiteURL string, recaptchaKey string) (string,
break
}
}

if response["solution"] == nil {
return "", errors.Errorf("Failed to get a response")
}
return response["solution"].(map[string]interface{})["gRecaptchaResponse"].(string), nil
}

Expand Down Expand Up @@ -134,6 +143,9 @@ func (c *Client) createTaskImage(imgString string) (float64, error) {
// Decode response
responseBody := make(map[string]interface{})
json.NewDecoder(resp.Body).Decode(&responseBody)
if reflect.ValueOf(responseBody["taskId"]).IsNil() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source is not formatted in canonical gofmt style

Suggested change
if reflect.ValueOf(responseBody["taskId"]).IsNil() {
if reflect.ValueOf(responseBody["taskId"]).IsNil() {

return "", errors.Errorf("Failed to get a response")
}
// TODO treat api errors and handle them properly
return responseBody["taskId"].(float64), nil
}
Expand Down