feat: log error

This commit is contained in:
Roi Feng
2025-02-16 00:56:10 -05:00
parent 07536a00d4
commit dd874418fc
8 changed files with 53 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"server_torii/internal/action"
@ -57,12 +58,19 @@ func CheckCaptcha(r *http.Request, reqData dataType.UserRequest, ruleSet *config
resp, err := http.PostForm("https://api.hcaptcha.com/siteverify", data)
if err != nil {
log.Printf("Error sending request to hCaptcha: %v", err)
decision.SetResponse(action.Done, []byte("500"), []byte("bad"))
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Printf("Error closing response body: %v", err)
}
}(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Printf("Error reading response from hCaptcha: %v", err)
decision.SetResponse(action.Done, []byte("500"), []byte("bad"))
return
}
@ -70,6 +78,7 @@ func CheckCaptcha(r *http.Request, reqData dataType.UserRequest, ruleSet *config
var hCaptchaResp HCaptchaResponse
err = json.Unmarshal(body, &hCaptchaResp)
if err != nil {
log.Printf("Error parsing response from hCaptcha: %v", err)
decision.SetResponse(action.Done, []byte("500"), []byte("bad"))
return
}
@ -105,6 +114,7 @@ func verifyClearanceCookie(reqData dataType.UserRequest, ruleSet config.RuleSet)
timeNow := time.Now().Unix()
parsedTimestamp, err := strconv.ParseInt(timestamp, 10, 64)
if err != nil {
log.Printf("Error parsing timestamp: %v", err)
return false
}