Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (31 sloc) 662 Bytes
package mackerel
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
)
// APIError represents the error type from Mackerel API.
type APIError struct {
StatusCode int
Message string
}
func (err *APIError) Error() string {
return fmt.Sprintf("API request failed: %s", err.Message)
}
func extractErrorMessage(r io.Reader) (errorMessage string) {
bs, err := ioutil.ReadAll(r)
if err != nil {
return
}
var data struct{ Error struct{ Message string } }
err = json.Unmarshal(bs, &data)
if err == nil {
errorMessage = data.Error.Message
} else {
var data struct{ Error string }
json.Unmarshal(bs, &data)
errorMessage = data.Error
}
return
}
You can’t perform that action at this time.