func NewAPIError(code int, content []byte) error {
	var errDef errorDefinition
	switch {
	case code == http.StatusBadRequest:
		errDef = &badRequestDef{}
	case code == http.StatusUnauthorized:
		errDef = &simpleErrDef{code: ErrCodeUnauthorized}
	case code == http.StatusForbidden:
		errDef = &simpleErrDef{code: ErrCodeForbidden}
	case code == http.StatusNotFound:
		errDef = &simpleErrDef{code: ErrCodeNotFound}
	case code == http.StatusConflict:
		errDef = &conflictDef{}
	case code == 422:
		errDef = &unprocessableEntityDef{}
	case code >= http.StatusInternalServerError:
		errDef = &simpleErrDef{code: ErrCodeServer}
	default:
		errDef = &simpleErrDef{code: ErrCodeUnknown}
	}
	return parseContent(errDef, content)
}
NewAPIError creates a new APIError instance from the given response code and content.
package marathon
import (
	"encoding/json"
	"fmt"
	"net/http"
	"strings"
)
const (
	ErrCodeBadRequest = iota
	ErrCodeUnauthorized
	ErrCodeForbidden
	ErrCodeNotFound
	ErrCodeDuplicateID
	ErrCodeAppLocked
	ErrCodeInvalidBean
	ErrCodeServer
	ErrCodeUnknown
)
type InvalidEndpointError struct {
	message string
}
func (e *InvalidEndpointError) Error() string {
	return e.message
}
func newInvalidEndpointError(message string, args ...interface{}) error {
	return &InvalidEndpointError{message: fmt.Sprintf(message, args)}
}
type APIError struct {
	ErrCode int
	message string
}
func (e *APIError) Error() string {
	return fmt.Sprintf("Marathon API error: %s", e.message)
}