2016-12-29 20:02:06 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-04-03 10:22:08 +00:00
|
|
|
// ErrMissingAnnotations the ingress rule does not contain annotations
|
2016-12-29 20:02:06 +00:00
|
|
|
// This is an error only when annotations are being parsed
|
|
|
|
ErrMissingAnnotations = errors.New("ingress rule without annotations")
|
|
|
|
|
|
|
|
// ErrInvalidAnnotationName the ingress rule does contains an invalid
|
|
|
|
// annotation name
|
|
|
|
ErrInvalidAnnotationName = errors.New("invalid annotation name")
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewInvalidAnnotationContent returns a new InvalidContent error
|
2017-01-20 22:37:59 +00:00
|
|
|
func NewInvalidAnnotationContent(name string, val interface{}) error {
|
2016-12-29 20:02:06 +00:00
|
|
|
return InvalidContent{
|
2017-04-03 10:22:08 +00:00
|
|
|
Name: fmt.Sprintf("the annotation %v does not contain a valid value (%v)", name, val),
|
2016-12-29 20:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewLocationDenied returns a new LocationDenied error
|
|
|
|
func NewLocationDenied(reason string) error {
|
|
|
|
return LocationDenied{
|
|
|
|
Reason: errors.Errorf("Location denied, reason: %v", reason),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// InvalidContent error
|
|
|
|
type InvalidContent struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e InvalidContent) Error() string {
|
|
|
|
return e.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
// LocationDenied error
|
|
|
|
type LocationDenied struct {
|
|
|
|
Reason error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e LocationDenied) Error() string {
|
|
|
|
return e.Reason.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsLocationDenied checks if the err is an error which
|
|
|
|
// indicates a location should return HTTP code 503
|
|
|
|
func IsLocationDenied(e error) bool {
|
|
|
|
_, ok := e.(LocationDenied)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsMissingAnnotations checks if the err is an error which
|
2017-04-03 10:22:08 +00:00
|
|
|
// indicates the ingress does not contain annotations
|
2016-12-29 20:02:06 +00:00
|
|
|
func IsMissingAnnotations(e error) bool {
|
|
|
|
return e == ErrMissingAnnotations
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsInvalidContent checks if the err is an error which
|
|
|
|
// indicates an annotations value is not valid
|
|
|
|
func IsInvalidContent(e error) bool {
|
|
|
|
_, ok := e.(InvalidContent)
|
|
|
|
return ok
|
|
|
|
}
|
2017-08-19 21:13:02 +00:00
|
|
|
|
2017-12-02 15:02:00 +00:00
|
|
|
// New returns a new error
|
2017-08-19 21:13:02 +00:00
|
|
|
func New(m string) error {
|
|
|
|
return errors.New(m)
|
|
|
|
}
|
|
|
|
|
2017-12-02 15:02:00 +00:00
|
|
|
// Errorf formats according to a format specifier and returns the string
|
|
|
|
// as a value that satisfies error.
|
2017-08-19 21:13:02 +00:00
|
|
|
func Errorf(format string, args ...interface{}) error {
|
|
|
|
return errors.Errorf(format, args)
|
|
|
|
}
|