Browse Source

Handle plugin list not implemented

Signed-off-by: Christopher Crone <christopher.crone@docker.com>
Christopher Crone 7 years ago
parent
commit
e7e11bdd44
2 changed files with 23 additions and 1 deletions
  1. 22 0
      client/errors.go
  2. 1 1
      client/plugin_list.go

+ 22 - 0
client/errors.go

@@ -64,6 +64,8 @@ func wrapResponseError(err error, resp serverResponse, object, id string) error
 		return nil
 	case resp.statusCode == http.StatusNotFound:
 		return objectNotFoundError{object: object, id: id}
+	case resp.statusCode == http.StatusNotImplemented:
+		return notImplementedError{message: err.Error()}
 	default:
 		return err
 	}
@@ -157,6 +159,26 @@ func IsErrPluginPermissionDenied(err error) bool {
 	return ok
 }
 
+type notImplementedError struct {
+	message string
+}
+
+func (e notImplementedError) Error() string {
+	return e.message
+}
+
+func (e notImplementedError) NotImplemented() bool {
+	return true
+}
+
+// IsNotImplementedError returns true if the error is a NotImplemented error.
+// This is returned by the API when a requested feature has not been
+// implemented.
+func IsNotImplementedError(err error) bool {
+	te, ok := err.(notImplementedError)
+	return ok && te.NotImplemented()
+}
+
 // NewVersionError returns an error if the APIVersion required
 // if less than the current supported version
 func (cli *Client) NewVersionError(APIrequired, feature string) error {

+ 1 - 1
client/plugin_list.go

@@ -23,7 +23,7 @@ func (cli *Client) PluginList(ctx context.Context, filter filters.Args) (types.P
 	}
 	resp, err := cli.get(ctx, "/plugins", query, nil)
 	if err != nil {
-		return plugins, err
+		return plugins, wrapResponseError(err, resp, "plugin", "")
 	}
 
 	err = json.NewDecoder(resp.body).Decode(&plugins)