aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 22:18:18 +0200
committerTeddy Wing2017-06-03 22:18:18 +0200
commitf8821fa88888491bf49d8cd626f7a011665c6066 (patch)
treeff4b33480a1e6976eb2e91ea688896e8bb6f8724
parentaa2f0f0bac6cc533b70265c9de60943abefa5931 (diff)
parent7f19527d1a89b44ae559861c5f33cf126c3b011c (diff)
downloadtimetasker-f8821fa88888491bf49d8cd626f7a011665c6066.tar.bz2
Merge branch 'handle-failing-responses-from-the-server' into timetasker-daily
-rw-r--r--TODO3
-rw-r--r--main.go20
2 files changed, 17 insertions, 6 deletions
diff --git a/TODO b/TODO
index 08cdf7b..2065140 100644
--- a/TODO
+++ b/TODO
@@ -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
diff --git a/main.go b/main.go
index 3b7ace5..861dc8b 100644
--- a/main.go
+++ b/main.go
@@ -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)
+ }
}