summaryrefslogtreecommitdiff
path: root/bilibili
diff options
context:
space:
mode:
Diffstat (limited to 'bilibili')
-rw-r--r--bilibili/request.go2
-rw-r--r--bilibili/request_test.go14
2 files changed, 15 insertions, 1 deletions
diff --git a/bilibili/request.go b/bilibili/request.go
index cb989a7..c31cf75 100644
--- a/bilibili/request.go
+++ b/bilibili/request.go
@@ -38,11 +38,11 @@ func callGet[T BaseResponse[V], V any](b Bilibili, url string) (resp T, err erro
}
r, err := b.http.Do(req)
- defer func() { _ = r.Body.Close() }()
if err != nil {
logger.Printf("ERROR: HTTP Request failed on API %v: %v", url, err)
return
}
+ defer func() { _ = r.Body.Close() }()
err = validateHttpStatus(r)
if err != nil {
diff --git a/bilibili/request_test.go b/bilibili/request_test.go
new file mode 100644
index 0000000..68e5c7a
--- /dev/null
+++ b/bilibili/request_test.go
@@ -0,0 +1,14 @@
+package bilibili
+
+import (
+ "testing"
+)
+
+func Test_callGet(t *testing.T) {
+ // an always-fail request should not panic
+ bi := NewBilibili()
+ _, err := callGet[BaseResponse[struct{}]](bi, "https://256.256.256.256")
+ if err == nil {
+ t.Fatalf("the artificial request should fail, but it haven't")
+ }
+}