Skip to content

Commit

Permalink
feat(client): handle status code 403
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Aug 25, 2022
1 parent 560f1d4 commit 44b6c14
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pkg/client/get_html.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func makeGetHTMLResult(ctx context.Context, resp *http.Response) (res GetHTMLRes
if err != nil {
return
}

err = handleStatusForbidden(ctx, &res)
if err != nil {
return
}
err = handleCaptcha(ctx, &res)
if err != nil {
return
Expand Down Expand Up @@ -105,6 +108,20 @@ func handleJSProtect(ctx context.Context, res *GetHTMLResult) (err error) {
return
}

func handleStatusForbidden(ctx context.Context, res *GetHTMLResult) (err error) {
if res.response.StatusCode != http.StatusForbidden {
return
}
time.Sleep(CaptchaDelay)
var c = For(ctx)
resp, err := c.Do(res.Request())
if err != nil {
return
}
*res, err = makeGetHTMLResult(ctx, resp)
return
}

func handleCaptcha(ctx context.Context, res *GetHTMLResult) (err error) {
if !bytes.Contains(res.Body(), []byte("/TCaptcha.js\"")) {
return
Expand Down

0 comments on commit 44b6c14

Please sign in to comment.