Browse code

Handle plugin list not implemented

Signed-off-by: Christopher Crone <christopher.crone@docker.com>

Christopher Crone authored on 2017/09/21 01:00:55
Showing 2 changed files
... ...
@@ -64,6 +64,8 @@ func wrapResponseError(err error, resp serverResponse, object, id string) error
64 64
 		return nil
65 65
 	case resp.statusCode == http.StatusNotFound:
66 66
 		return objectNotFoundError{object: object, id: id}
67
+	case resp.statusCode == http.StatusNotImplemented:
68
+		return notImplementedError{message: err.Error()}
67 69
 	default:
68 70
 		return err
69 71
 	}
... ...
@@ -157,6 +159,26 @@ func IsErrPluginPermissionDenied(err error) bool {
157 157
 	return ok
158 158
 }
159 159
 
160
+type notImplementedError struct {
161
+	message string
162
+}
163
+
164
+func (e notImplementedError) Error() string {
165
+	return e.message
166
+}
167
+
168
+func (e notImplementedError) NotImplemented() bool {
169
+	return true
170
+}
171
+
172
+// IsNotImplementedError returns true if the error is a NotImplemented error.
173
+// This is returned by the API when a requested feature has not been
174
+// implemented.
175
+func IsNotImplementedError(err error) bool {
176
+	te, ok := err.(notImplementedError)
177
+	return ok && te.NotImplemented()
178
+}
179
+
160 180
 // NewVersionError returns an error if the APIVersion required
161 181
 // if less than the current supported version
162 182
 func (cli *Client) NewVersionError(APIrequired, feature string) error {
... ...
@@ -23,7 +23,7 @@ func (cli *Client) PluginList(ctx context.Context, filter filters.Args) (types.P
23 23
 	}
24 24
 	resp, err := cli.get(ctx, "/plugins", query, nil)
25 25
 	if err != nil {
26
-		return plugins, err
26
+		return plugins, wrapResponseError(err, resp, "plugin", "")
27 27
 	}
28 28
 
29 29
 	err = json.NewDecoder(resp.body).Decode(&plugins)