From 014537e1eab6fe97793c153a11a7869baf5afeb3 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sun, 16 Jul 2023 11:10:07 +0800 Subject: [PATCH] fix: discard http unsuccessful status --- component/resource/vehicle.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/component/resource/vehicle.go b/component/resource/vehicle.go index 927a9604..1ae1b662 100644 --- a/component/resource/vehicle.go +++ b/component/resource/vehicle.go @@ -2,12 +2,14 @@ package resource import ( "context" - clashHttp "github.com/Dreamacro/clash/component/http" - types "github.com/Dreamacro/clash/constant/provider" + "errors" "io" "net/http" "os" "time" + + clashHttp "github.com/Dreamacro/clash/component/http" + types "github.com/Dreamacro/clash/constant/provider" ) type FileVehicle struct { @@ -54,8 +56,10 @@ func (h *HTTPVehicle) Read() ([]byte, error) { if err != nil { return nil, err } - defer resp.Body.Close() + if resp.StatusCode < 200 && resp.StatusCode > 299 { + return nil, errors.New(resp.Status) + } buf, err := io.ReadAll(resp.Body) if err != nil { return nil, err