improved error handling

This commit is contained in:
Mira Weller 2020-06-08 14:16:58 +01:00
parent 14569a0cdc
commit 5f2cfb4f75

View File

@ -9,6 +9,7 @@ import (
"net/http"
"flag"
"log"
"fmt"
"goftp.io/server"
)
@ -78,7 +79,12 @@ func (driver *ForwarderDriver) PutFile(destPath string, data io.Reader, appendDa
client := &http.Client{}
req, err := http.NewRequest("PUT", driver.TargetURL + url.QueryEscape(destPath), data)
resp, err := client.Do(req)
return resp.Request.ContentLength, err
log.Printf("Status: %v, Transferred bytes: %v, errmes: %v", resp.Status, resp.Request.ContentLength, err)
if resp.StatusCode >= 300 {
return 0, fmt.Errorf("server returned error status %s", resp.Status)
}
return resp.Request.ContentLength, err
}
type ForwarderDriverFactory struct {