Fix more lint errors
This commit is contained in:
parent
cf51c065d0
commit
3967367eed
@ -2,10 +2,12 @@ package scraper
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -144,6 +146,11 @@ func (api *API) update_csrf_token() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func is_timeout(err error) bool {
|
||||||
|
var urlErr *url.Error
|
||||||
|
return errors.As(err, &urlErr) && urlErr.Timeout()
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) do_http_POST(remote_url string, body string, result interface{}) error {
|
func (api *API) do_http_POST(remote_url string, body string, result interface{}) error {
|
||||||
req, err := http.NewRequest("POST", remote_url, strings.NewReader(body))
|
req, err := http.NewRequest("POST", remote_url, strings.NewReader(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +168,7 @@ func (api *API) do_http_POST(remote_url string, body string, result interface{})
|
|||||||
log.Debug(" " + body)
|
log.Debug(" " + body)
|
||||||
|
|
||||||
resp, err := api.Client.Do(req)
|
resp, err := api.Client.Do(req)
|
||||||
if urlErr, ok := err.(*url.Error); ok && urlErr.Timeout() {
|
if is_timeout(err) {
|
||||||
return fmt.Errorf("POST %q:\n %w", remote_url, ErrRequestTimeout)
|
return fmt.Errorf("POST %q:\n %w", remote_url, ErrRequestTimeout)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return fmt.Errorf("Error executing HTTP POST request:\n %w", err)
|
return fmt.Errorf("Error executing HTTP POST request:\n %w", err)
|
||||||
@ -212,7 +219,7 @@ func (api *API) do_http(remote_url string, cursor string, result interface{}) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, err := api.Client.Do(req)
|
resp, err := api.Client.Do(req)
|
||||||
if urlErr, ok := err.(*url.Error); ok && urlErr.Timeout() {
|
if is_timeout(err) {
|
||||||
return fmt.Errorf("GET %q:\n %w", remote_url, ErrRequestTimeout)
|
return fmt.Errorf("GET %q:\n %w", remote_url, ErrRequestTimeout)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return fmt.Errorf("Error executing HTTP request:\n %w", err)
|
return fmt.Errorf("Error executing HTTP request:\n %w", err)
|
||||||
@ -390,7 +397,7 @@ func (api *API) DownloadMedia(remote_url string) ([]byte, error) {
|
|||||||
// req.Header.Set("Referer", "https://twitter.com/") // DM embedded images require this header
|
// req.Header.Set("Referer", "https://twitter.com/") // DM embedded images require this header
|
||||||
|
|
||||||
resp, err := api.Client.Do(req)
|
resp, err := api.Client.Do(req)
|
||||||
if urlErr, ok := err.(*url.Error); ok && urlErr.Timeout() {
|
if is_timeout(err) {
|
||||||
return []byte{}, fmt.Errorf("GET %q:\n %w", remote_url, ErrRequestTimeout)
|
return []byte{}, fmt.Errorf("GET %q:\n %w", remote_url, ErrRequestTimeout)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return []byte{}, fmt.Errorf("Error executing HTTP request:\n %w", err)
|
return []byte{}, fmt.Errorf("Error executing HTTP request:\n %w", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user