Skip to content

Commit

Permalink
Handle HTTP errors specially
Browse files Browse the repository at this point in the history
Otherwise, simply logging the error prints the client ID
and client secret to console in plain text as part of the
URL.
  • Loading branch information
nishanths committed Jul 31, 2016
1 parent 5e8dc23 commit a497bee
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -65,7 +66,7 @@ func doUpdate() error {

lics, err := c.List()
if err != nil {
return err
return convertAPIError(err)
}

f, err := os.Create(filepath.Join(tempRoot, "data", "licenses.json"))
Expand All @@ -90,7 +91,7 @@ func doUpdate() error {

l, err := c.Info(l.Key)
if err != nil {
errs[i] = err
errs[i] = convertAPIError(err)
return
}

Expand Down Expand Up @@ -125,8 +126,22 @@ func doUpdate() error {
return os.Rename(tempRoot, licensePath)
}

// convertAPIError handles HTTP errors as a special case
// because simply logging the error may print the client ID
// and client secret as part of the error message URL.
func convertAPIError(err error) error {
switch err.(type) {
case nil:
return nil
case license.StatusError:
return err
default:
return errors.New("error: failed to fetch licenses")
}
}

var (
// placeholders is a map from placeholders in the JSON
// placeholders is a map from placeholders in GitHub's JSON
// to placeholders we use in templates.
// The keys should be kept in sync with the regex below.
placeholders = map[string]string{
Expand Down

0 comments on commit a497bee

Please sign in to comment.