From 20c1a2b928647fa80931caa781f238a11deca5c5 Mon Sep 17 00:00:00 2001 From: Christopher Crone Date: Wed, 20 Sep 2017 18:00:55 +0200 Subject: [PATCH] Handle plugin list not implemented Signed-off-by: Christopher Crone Upstream-commit: e7e11bdd44878d28c642d72761aa41eb9ffce3d1 Component: engine --- components/engine/client/errors.go | 22 ++++++++++++++++++++++ components/engine/client/plugin_list.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/components/engine/client/errors.go b/components/engine/client/errors.go index cad4521757..3f52dfe5f6 100644 --- a/components/engine/client/errors.go +++ b/components/engine/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 { diff --git a/components/engine/client/plugin_list.go b/components/engine/client/plugin_list.go index 3acde3b966..78dbeb8be3 100644 --- a/components/engine/client/plugin_list.go +++ b/components/engine/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)