代码拉取完成,页面将自动刷新
package client
import (
"encoding/json"
"fmt"
"net/http"
"github.com/go-resty/resty"
"github.com/sensu/sensu-go/backend/apid/actions"
)
// APIError describes an error message returned by the REST API
type APIError struct {
Message string `json:"message"`
Code uint32 `json:"code,omitempty"`
}
func (a APIError) Error() string {
return a.Message
}
// UnmarshalError decode the API error
// TODO: Export err type from routers package.
func UnmarshalError(res *resty.Response) error {
var apiErr APIError
switch res.StatusCode() {
case http.StatusPaymentRequired:
apiErr.Code = uint32(actions.PaymentRequired)
apiErr.Message = "This functionality requires a valid Sensu Go license. Please install a valid license file and restart or contact Sales for a trial."
default:
if err := json.Unmarshal(res.Body(), &apiErr); err != nil {
if len(res.Body()) > 0 {
apiErr.Message = string(res.Body())
} else {
apiErr.Message = fmt.Sprintf("the API returned: %s", res.Status())
}
}
}
return apiErr
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。