libnet: Replace NoServiceError with UnavailableError
UnavailableError is now compatible with errdefs.UnavailableError. These errors will now return a 503 instead of a 500. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
parent
42d34e40f9
commit
bd0111c1f4
3 changed files with 14 additions and 14 deletions
|
@ -32,8 +32,8 @@ var (
|
||||||
ErrInvalidAddressSpace = types.InvalidParameterErrorf("Invalid Address Space")
|
ErrInvalidAddressSpace = types.InvalidParameterErrorf("Invalid Address Space")
|
||||||
ErrInvalidPool = types.InvalidParameterErrorf("Invalid Address Pool")
|
ErrInvalidPool = types.InvalidParameterErrorf("Invalid Address Pool")
|
||||||
ErrInvalidSubPool = types.InvalidParameterErrorf("Invalid Address SubPool")
|
ErrInvalidSubPool = types.InvalidParameterErrorf("Invalid Address SubPool")
|
||||||
ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool")
|
ErrNoAvailableIPs = types.UnavailableErrorf("No available addresses on this pool")
|
||||||
ErrNoIPReturned = types.NoServiceErrorf("No address returned")
|
ErrNoIPReturned = types.UnavailableErrorf("No address returned")
|
||||||
ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
|
ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
|
||||||
ErrIPOutOfRange = types.InvalidParameterErrorf("Requested address is out of range")
|
ErrIPOutOfRange = types.InvalidParameterErrorf("Requested address is out of range")
|
||||||
ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
|
ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")
|
||||||
|
|
|
@ -374,10 +374,10 @@ type ForbiddenError interface {
|
||||||
Forbidden()
|
Forbidden()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoServiceError is an interface for errors returned when the required service is not available
|
// UnavailableError is an interface for errors returned when the required service is not available
|
||||||
type NoServiceError interface {
|
type UnavailableError interface {
|
||||||
// NoService makes implementer into NoServiceError type
|
// Unavailable makes implementer into UnavailableError type
|
||||||
NoService()
|
Unavailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotImplementedError is an interface for errors raised because of requested functionality is not yet implemented
|
// NotImplementedError is an interface for errors raised because of requested functionality is not yet implemented
|
||||||
|
@ -411,9 +411,9 @@ func ForbiddenErrorf(format string, params ...interface{}) error {
|
||||||
return forbidden(fmt.Sprintf(format, params...))
|
return forbidden(fmt.Sprintf(format, params...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoServiceErrorf creates an instance of NoServiceError
|
// UnavailableErrorf creates an instance of UnavailableError
|
||||||
func NoServiceErrorf(format string, params ...interface{}) error {
|
func UnavailableErrorf(format string, params ...interface{}) error {
|
||||||
return noService(fmt.Sprintf(format, params...))
|
return unavailable(fmt.Sprintf(format, params...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotImplementedErrorf creates an instance of NotImplementedError
|
// NotImplementedErrorf creates an instance of NotImplementedError
|
||||||
|
@ -448,12 +448,12 @@ func (frb forbidden) Error() string {
|
||||||
}
|
}
|
||||||
func (frb forbidden) Forbidden() {}
|
func (frb forbidden) Forbidden() {}
|
||||||
|
|
||||||
type noService string
|
type unavailable string
|
||||||
|
|
||||||
func (ns noService) Error() string {
|
func (ns unavailable) Error() string {
|
||||||
return string(ns)
|
return string(ns)
|
||||||
}
|
}
|
||||||
func (ns noService) NoService() {}
|
func (ns unavailable) Unavailable() {}
|
||||||
|
|
||||||
type notImpl string
|
type notImpl string
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,11 @@ func TestErrorConstructors(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = NoServiceErrorf("Driver %s is not available", "mh")
|
err = UnavailableErrorf("Driver %s is not available", "mh")
|
||||||
if err.Error() != "Driver mh is not available" {
|
if err.Error() != "Driver mh is not available" {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, ok := err.(NoServiceError); !ok {
|
if _, ok := err.(UnavailableError); !ok {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if _, ok := err.(MaskableError); ok {
|
if _, ok := err.(MaskableError); ok {
|
||||||
|
|
Loading…
Reference in a new issue