diff options
| author | Teddy Wing | 2017-06-03 22:18:18 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-06-03 22:18:18 +0200 | 
| commit | f8821fa88888491bf49d8cd626f7a011665c6066 (patch) | |
| tree | ff4b33480a1e6976eb2e91ea688896e8bb6f8724 | |
| parent | aa2f0f0bac6cc533b70265c9de60943abefa5931 (diff) | |
| parent | 7f19527d1a89b44ae559861c5f33cf126c3b011c (diff) | |
| download | timetasker-f8821fa88888491bf49d8cd626f7a011665c6066.tar.bz2 | |
Merge branch 'handle-failing-responses-from-the-server' into timetasker-daily
| -rw-r--r-- | TODO | 3 | ||||
| -rw-r--r-- | main.go | 20 | 
2 files changed, 17 insertions, 6 deletions
| @@ -7,7 +7,8 @@ v Command line arguments: (2017.06.03)  	v Date (optional, format: 2017-01-31)  	v Description (optional) -- Handle failing responses from the server (show errors to the user) +v Handle failing responses from the server (show errors to the user) +  (2017.06.03)  v Config (2017.06.03)  	v A `--write-config` or similar option that generates and write a bare  	  config for users to use @@ -3,8 +3,8 @@ package main  import (  	"fmt"  	"io/ioutil" -	"log"  	"os" +	"strings"  	"time"  	"github.com/teddywing/timetasker/timetask" @@ -97,17 +97,27 @@ func main() {  		password,  	)  	kingpin.FatalIfError(err, "login request failed") -	log.Printf("%+v\n", resp)  	defer resp.Body.Close()  	body, err := ioutil.ReadAll(resp.Body) -	log.Println(string(body)) +	if strings.Contains( +		string(body), +		"The username and password don't appear to be valid.", +	) { +		kingpin.Errorf("TimeTask authentication failed") +		os.Exit(1) +	}  	resp, err = timetask.SubmitTimeEntry(*client, time_entry)  	kingpin.FatalIfError(err, "time entry submission request failed") -	log.Printf("%+v\n", resp)  	defer resp.Body.Close()  	body, err = ioutil.ReadAll(resp.Body) -	log.Println(string(body)) +	if strings.Contains( +		string(body), +		"No time entries were created.", +	) { +		kingpin.Errorf("time entry creation failed") +		os.Exit(1) +	}  } | 
