diff options
| author | Teddy Wing | 2017-06-04 00:38:28 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-04 00:38:28 +0200 | 
| commit | d4a9537b5671fafe04335b9f91c5d5869d4a2358 (patch) | |
| tree | 13d2a90f9074a2a609822d1294182a167fe5355f /main.go | |
| parent | 34fb8b7b98076b65b05efc2bbaff013fbbbf5116 (diff) | |
| download | timetasker-d4a9537b5671fafe04335b9f91c5d5869d4a2358.tar.bz2 | |
Move HTTP response body errors into http.go
Take the errors in `main()` that check the response body contents for
known error strings and put them in their respective functions in
"timetask/http.go".
Didn't really make sense to me that these functions were returning HTTP
responses that we weren't really using in a meaningful way. Instead they
should just do their thing and let us know if there was a problem.
That includes checking to see if there were any non-standard errors,
like the ones we had custom-built. Now all that handling and
error-making is self-contained, which feels much nicer.
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 26 | 
1 files changed, 2 insertions, 24 deletions
| @@ -2,9 +2,7 @@ package main  import (  	"fmt" -	"io/ioutil"  	"os" -	"strings"  	"time"  	"github.com/teddywing/timetasker/timetask" @@ -93,22 +91,12 @@ func main() {  	password, err := passwordCmd(config.Auth.PasswordCmd)  	kingpin.FatalIfError(err, "password command failed") -	resp, client, err := timetask.Login( +	client, err := timetask.Login(  		config.Auth.Username,  		password,  	)  	kingpin.FatalIfError(err, "login request failed") -	defer resp.Body.Close() -	body, err := ioutil.ReadAll(resp.Body) -	if strings.Contains( -		string(body), -		"The username and password don't appear to be valid.", -	) { -		kingpin.Errorf("TimeTask authentication failed") -		os.Exit(1) -	} -  	// List modules  	if *list_modules {  		modules, err := timetask.RequestModules(*client, time_entry) @@ -118,16 +106,6 @@ func main() {  		os.Exit(0)  	} -	resp, err = timetask.SubmitTimeEntry(*client, time_entry) +	err = timetask.SubmitTimeEntry(*client, time_entry)  	kingpin.FatalIfError(err, "time entry submission request failed") - -	defer resp.Body.Close() -	body, err = ioutil.ReadAll(resp.Body) -	if strings.Contains( -		string(body), -		"No time entries were created.", -	) { -		kingpin.Errorf("time entry creation failed") -		os.Exit(1) -	}  } | 
