diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 777f9e77b..944754644 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,6 +17,10 @@ |=== | | Description | PR +| 🐣 +| Improve error handling in clients +| https://github.com/knative/client/pull/1154[#1154] + | 🎁 | Add machine readable output (-o flag) to kn source ping describe | https://github.com/knative/client/pull/1150[#1150] diff --git a/pkg/sources/v1alpha2/apiserver_client.go b/pkg/sources/v1alpha2/apiserver_client.go index 9d90335cf..285255e7f 100644 --- a/pkg/sources/v1alpha2/apiserver_client.go +++ b/pkg/sources/v1alpha2/apiserver_client.go @@ -104,7 +104,10 @@ func (c *apiServerSourcesClient) UpdateAPIServerSource(apiSource *v1alpha2.ApiSe //DeleteAPIServerSource is used to create an instance of ApiServerSource func (c *apiServerSourcesClient) DeleteAPIServerSource(name string) error { err := c.client.Delete(context.TODO(), name, metav1.DeleteOptions{}) - return err + if err != nil { + return knerrors.GetError(err) + } + return nil } // Return the client's namespace diff --git a/pkg/sources/v1alpha2/ping_client.go b/pkg/sources/v1alpha2/ping_client.go index c3fe9adc8..029d3f85d 100644 --- a/pkg/sources/v1alpha2/ping_client.go +++ b/pkg/sources/v1alpha2/ping_client.go @@ -76,16 +76,26 @@ func (c *pingSourcesClient) CreatePingSource(pingsource *v1alpha2.PingSource) er return fmt.Errorf("a sink is required for creating a source") } _, err := c.client.Create(context.TODO(), pingsource, metav1.CreateOptions{}) - return err + if err != nil { + return knerrors.GetError(err) + } + return nil } func (c *pingSourcesClient) UpdatePingSource(pingSource *v1alpha2.PingSource) error { _, err := c.client.Update(context.TODO(), pingSource, metav1.UpdateOptions{}) - return err + if err != nil { + return knerrors.GetError(err) + } + return nil } func (c *pingSourcesClient) DeletePingSource(name string) error { - return c.client.Delete(context.TODO(), name, metav1.DeleteOptions{}) + err := c.client.Delete(context.TODO(), name, metav1.DeleteOptions{}) + if err != nil { + return knerrors.GetError(err) + } + return nil } func (c *pingSourcesClient) GetPingSource(name string) (*v1alpha2.PingSource, error) { @@ -104,7 +114,7 @@ func (c *pingSourcesClient) GetPingSource(name string) (*v1alpha2.PingSource, er func (c *pingSourcesClient) ListPingSource() (*v1alpha2.PingSourceList, error) { sourceList, err := c.client.List(context.TODO(), metav1.ListOptions{}) if err != nil { - return nil, err + return nil, knerrors.GetError(err) } return updatePingSourceListGVK(sourceList)