Skip to content

Commit

Permalink
Check for content-type application/json.
Browse files Browse the repository at this point in the history
Hopefully fixes #3.
  • Loading branch information
mtricht committed Dec 2, 2016
1 parent 8f83e40 commit 8fe9487
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/views.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 27 additions & 9 deletions src/backend/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ type action struct {
}

type cardResult struct {
Error error
Date string
Complete bool
Points float64
Error error
Date string
Complete bool
Points float64
TrelloError bool
}

func Start() {
Expand All @@ -79,12 +80,16 @@ func runBoards() {
func Run(boardID string) {
log.Printf("Checking board ID #%s", boardID)
board, err := getBoard(boardID)
board.ID = boardID
log.Printf("Board name: %s", board.Name)
lastListID := getLastList(board)
if err != nil {
log.Fatalln(err)
}
if board == nil {
log.Println("Something went wrong requesting a board from Trello.")
return
}
board.ID = boardID
log.Printf("Board name: %s", board.Name)
lastListID := getLastList(board)
resultChannel := make(chan *cardResult)
for _, card := range board.Cards {
go determineCardComplete(card, lastListID, resultChannel)
Expand All @@ -95,6 +100,10 @@ func Run(boardID string) {
if response.Error != nil {
log.Fatalln(response.Error)
}
if response.TrelloError {
log.Println("Something went wrong requesting a card from Trello.")
return
}
if response.Complete {
board.CardsCompleted++
board.PointsCompleted += response.Points
Expand Down Expand Up @@ -122,12 +131,15 @@ func getBoard(id string) (*board, error) {
resp, err := http.Get(url)
defer resp.Body.Close()
if err != nil {
return &board{}, err
return nil, err
}
if resp.Header.Get("Content-Type") != "application/json; charset=utf-8" {
return nil, nil
}
r := new(board)
err = json.NewDecoder(resp.Body).Decode(r)
if err != nil {
return &board{}, err
return nil, err
}
return r, nil
}
Expand Down Expand Up @@ -166,6 +178,12 @@ func determineCardComplete(card card, listID string, res chan *cardResult) {
}
return
}
if resp.Header.Get("Content-Type") != "application/json; charset=utf-8" {
res <- &cardResult{
TrelloError: true,
}
return
}
var actions []action
err = json.NewDecoder(resp.Body).Decode(&actions)
if err != nil {
Expand Down

0 comments on commit 8fe9487

Please sign in to comment.