Skip to content

Commit

Permalink
add checking http status code with out of range 200-299
Browse files Browse the repository at this point in the history
  • Loading branch information
hbakhtiyor committed Dec 19, 2018
1 parent 7866d0d commit 3d5a6c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func main() {
return
}

// TODO [Copied to clipboard]
// https://github.com/atotto/clipboard ?
fmt.Printf("\n%s: %v\n", programName, result.ShortenedURL)
}
}
Expand Down
22 changes: 11 additions & 11 deletions wetransfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func GetDirectLink(rawURL string) (string, error) {
if err != nil {
return "", err
}
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
log.Printf("GetDirectLink: Error occurs while processing HEAD request: %s %v\n", rawURL, response)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func GetDirectLink(rawURL string) (string, error) {
return "", err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("GetDirectLink: Error occurs while processing POST request: %s %s %v\n", rawURL, bodyBytes, response)
Expand Down Expand Up @@ -194,7 +194,7 @@ func DownloadFile(rawURL string) error {
return err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("DownloadFile: Error occurs while processing GET request: %s %s %v\n", rawURL, bodyBytes, response)
Expand Down Expand Up @@ -235,7 +235,7 @@ func PrepareEmailUpload(fileNames []string, message string, sender string, recip
return nil, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("PrepareEmailUpload: Error occurs while processing POST request: %s %v\n", bodyBytes, response)
Expand Down Expand Up @@ -282,7 +282,7 @@ func PrepareLinkUpload(fileNames []string, message string) (*WeID, error) {
return nil, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("PrepareLinkUpload: Error occurs while processing POST request: %s %v\n", bodyBytes, response)
Expand Down Expand Up @@ -331,7 +331,7 @@ func PrepareFileUpload(transferID string, filePath string) (*WeID, error) {
return nil, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("PrepareFileUpload: Error occurs while processing POST request: %s %v\n", bodyBytes, response)
Expand Down Expand Up @@ -368,7 +368,7 @@ func FinalizeUpload(transferID string) (*WeShortenedURL, error) {
return nil, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("FinalizeUpload: Error occurs while processing PUT request: %s %v\n", bodyBytes, response)
Expand Down Expand Up @@ -443,7 +443,7 @@ func UploadChunks(transferID string, fileID string, filePath string, defaultChun
return err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("UploadChunks: Error occurs while processing POST request: %s %v\n", bodyBytes, response)
Expand Down Expand Up @@ -474,7 +474,7 @@ func UploadChunks(transferID string, fileID string, filePath string, defaultChun
return err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("UploadChunks: Error occurs while processing OPTIONS request: %s %v\n", bodyBytes, response)
Expand All @@ -497,7 +497,7 @@ func UploadChunks(transferID string, fileID string, filePath string, defaultChun
return err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("UploadChunks: Error occurs while processing PUT request: %s %v\n", bodyBytes, response)
Expand Down Expand Up @@ -529,7 +529,7 @@ func UploadChunks(transferID string, fileID string, filePath string, defaultChun
return err
}
defer response.Body.Close()
if response.StatusCode != 200 {
if response.StatusCode < 200 || response.StatusCode > 299 {
if Debug {
bodyBytes, _ := ioutil.ReadAll(response.Body)
log.Printf("UploadChunks: Error occurs while processing PUT request: %s %v\n", bodyBytes, response)
Expand Down

0 comments on commit 3d5a6c5

Please sign in to comment.