瀏覽代碼

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>
Albin Kerouanton 1 年之前
父節點
當前提交
bd0111c1f4
共有 3 個文件被更改,包括 14 次插入14 次删除
  1. 2 2
      libnetwork/ipamapi/contract.go
  2. 10 10
      libnetwork/types/types.go
  3. 2 2
      libnetwork/types/types_test.go

+ 2 - 2
libnetwork/ipamapi/contract.go

@@ -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")

+ 10 - 10
libnetwork/types/types.go

@@ -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
 

+ 2 - 2
libnetwork/types/types_test.go

@@ -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 {