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:
Albin Kerouanton 2023-08-08 13:42:23 +02:00
parent 42d34e40f9
commit bd0111c1f4
No known key found for this signature in database
GPG key ID: 630B8E1DCBDB1864
3 changed files with 14 additions and 14 deletions

View file

@ -32,8 +32,8 @@ var (
ErrInvalidAddressSpace = types.InvalidParameterErrorf("Invalid Address Space")
ErrInvalidPool = types.InvalidParameterErrorf("Invalid Address Pool")
ErrInvalidSubPool = types.InvalidParameterErrorf("Invalid Address SubPool")
ErrNoAvailableIPs = types.NoServiceErrorf("No available addresses on this pool")
ErrNoIPReturned = types.NoServiceErrorf("No address returned")
ErrNoAvailableIPs = types.UnavailableErrorf("No available addresses on this pool")
ErrNoIPReturned = types.UnavailableErrorf("No address returned")
ErrIPAlreadyAllocated = types.ForbiddenErrorf("Address already in use")
ErrIPOutOfRange = types.InvalidParameterErrorf("Requested address is out of range")
ErrPoolOverlap = types.ForbiddenErrorf("Pool overlaps with other one on this address space")

View file

@ -374,10 +374,10 @@ type ForbiddenError interface {
Forbidden()
}
// NoServiceError is an interface for errors returned when the required service is not available
type NoServiceError interface {
// NoService makes implementer into NoServiceError type
NoService()
// UnavailableError is an interface for errors returned when the required service is not available
type UnavailableError interface {
// Unavailable makes implementer into UnavailableError type
Unavailable()
}
// 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...))
}
// NoServiceErrorf creates an instance of NoServiceError
func NoServiceErrorf(format string, params ...interface{}) error {
return noService(fmt.Sprintf(format, params...))
// UnavailableErrorf creates an instance of UnavailableError
func UnavailableErrorf(format string, params ...interface{}) error {
return unavailable(fmt.Sprintf(format, params...))
}
// NotImplementedErrorf creates an instance of NotImplementedError
@ -448,12 +448,12 @@ func (frb forbidden) Error() string {
}
func (frb forbidden) Forbidden() {}
type noService string
type unavailable string
func (ns noService) Error() string {
func (ns unavailable) Error() string {
return string(ns)
}
func (ns noService) NoService() {}
func (ns unavailable) Unavailable() {}
type notImpl string

View file

@ -52,11 +52,11 @@ func TestErrorConstructors(t *testing.T) {
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" {
t.Fatal(err)
}
if _, ok := err.(NoServiceError); !ok {
if _, ok := err.(UnavailableError); !ok {
t.Fatal(err)
}
if _, ok := err.(MaskableError); ok {