fix: discard http unsuccessful status

This commit is contained in:
Skyxim 2023-07-16 11:10:07 +08:00
parent 9b50f56e7c
commit 014537e1ea

View file

@ -2,12 +2,14 @@ package resource
import ( import (
"context" "context"
clashHttp "github.com/Dreamacro/clash/component/http" "errors"
types "github.com/Dreamacro/clash/constant/provider"
"io" "io"
"net/http" "net/http"
"os" "os"
"time" "time"
clashHttp "github.com/Dreamacro/clash/component/http"
types "github.com/Dreamacro/clash/constant/provider"
) )
type FileVehicle struct { type FileVehicle struct {
@ -54,8 +56,10 @@ func (h *HTTPVehicle) Read() ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode < 200 && resp.StatusCode > 299 {
return nil, errors.New(resp.Status)
}
buf, err := io.ReadAll(resp.Body) buf, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err