aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 22:13:30 +0200
committerTeddy Wing2017-06-03 22:13:30 +0200
commit8e7fb7199f1e1f84c914bbaa00fa057e3489f1e8 (patch)
treec34925389cf94cd608da2eab54a9ad1f75625e11 /main.go
parentaa2f0f0bac6cc533b70265c9de60943abefa5931 (diff)
downloadtimetasker-8e7fb7199f1e1f84c914bbaa00fa057e3489f1e8.tar.bz2
main(): Handle errors from HTTP responses
Add some simple error handling for known responses from our TimeTask HTTP requests. Check a couple of known strings to determine whether there was an error. If so, exit with a failing error code. Remove our old `log` statements. These were used during debugging to see some output and check responses from TimeTask. We now have an idea of what those responses are, and are handling some of the error cases. Thus the log statements are no longer needed.
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 15 insertions, 5 deletions
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)
+ }
}