Don't warn about AWS timeout
@@ -22,36 +22,48 @@ type aws struct {
func gatherAWS(util *Data, client *http.Client) error {
aws, err := getAWS(client)
if err != nil {
- // TODO only return an error if validation fails.
+ // Only return the error here if it is unexpected to prevent
+ // warning customers who aren't running AWS about a timeout.
+ if _, ok := err.(unexpectedAWSErr); ok {
return err
}
+ return nil
+ }
util.Vendors.AWS = aws
return nil
}
+type unexpectedAWSErr struct{ e error }
+
+func (e unexpectedAWSErr) Error() string {
+ return fmt.Sprintf("unexpected AWS error: %v", e.e)
+}
+
func getAWS(client *http.Client) (*aws, error) {
response, err := client.Get(awsEndpoint)
if err != nil {
+ // No unexpectedAWSErr here: A timeout is usually going to
+ // happen.
return nil, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
- return nil, fmt.Errorf("got response code %d", response.StatusCode)
+ return nil, unexpectedAWSErr{e: fmt.Errorf("response code %d", response.StatusCode)}
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
- return nil, err
+ return nil, unexpectedAWSErr{e: err}
}
a := &aws{}
if err := json.Unmarshal(data, a); err != nil {
- return nil, err
+ return nil, unexpectedAWSErr{e: err}
}
if err := a.validate(); err != nil {
- return nil, err
+ return nil, unexpectedAWSErr{e: err}
}
return a, nil
@@ -60,17 +72,17 @@ func getAWS(client *http.Client) (*aws, error) {
func (a *aws) validate() (err error) {
a.InstanceID, err = normalizeValue(a.InstanceID)
if err != nil {
- return fmt.Errorf("Invalid AWS instance ID: %v", err)
+ return fmt.Errorf("invalid instance ID: %v", err)
}
a.InstanceType, err = normalizeValue(a.InstanceType)
if err != nil {
- return fmt.Errorf("Invalid AWS instance type: %v", err)
+ return fmt.Errorf("invalid instance type: %v", err)
}
a.AvailabilityZone, err = normalizeValue(a.AvailabilityZone)
if err != nil {
- return fmt.Errorf("Invalid AWS availability zone: %v", err)
+ return fmt.Errorf("invalid availability zone: %v", err)
}
return
