fix exception when handling http status
This commit is contained in:
parent
4c3b736efb
commit
dae9c1cf45
@ -91,6 +91,10 @@ func (h *HTTP) Stat() (info fs.FileInfo, err error) {
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode > 399 {
|
||||
err = ErrTransportResourceAbsent
|
||||
return
|
||||
}
|
||||
fi := NewHTTPFileInfo(uri)
|
||||
contentLength := response.Header.Get("Content-Length")
|
||||
if contentLength != "" {
|
||||
|
@ -3,7 +3,7 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
_ "errors"
|
||||
"errors"
|
||||
_ "fmt"
|
||||
"net/url"
|
||||
"net/http"
|
||||
@ -15,6 +15,10 @@ _ "os"
|
||||
"context"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrTransportResourceAbsent error = errors.New("Transport resource is absent")
|
||||
)
|
||||
|
||||
type Handler interface {
|
||||
URI() *url.URL
|
||||
ContentType() string
|
||||
@ -162,11 +166,19 @@ func (r *Reader) AddHeader(name string, value string) {
|
||||
}
|
||||
|
||||
func (r *Reader) Status() string {
|
||||
return r.handle.(*HTTPReader).GetResponse().Status
|
||||
if httpReader, ok := r.handle.(*HTTPReader); ok {
|
||||
return httpReader.GetResponse().Status
|
||||
}
|
||||
panic("Unable to get HTTP status from reader")
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *Reader) StatusCode() int {
|
||||
return r.handle.(*HTTPReader).GetResponse().StatusCode
|
||||
if httpReader, ok := r.handle.(*HTTPReader); ok {
|
||||
return httpReader.GetResponse().StatusCode
|
||||
}
|
||||
panic("Unable to get HTTP status code from reader")
|
||||
return 0
|
||||
}
|
||||
|
||||
func (r *Reader) Response() *http.Response {
|
||||
|
Loading…
Reference in New Issue
Block a user