Skip to content

Commit

Permalink
improve error handling in clients
Browse files Browse the repository at this point in the history
Signed-off-by: Arghya Sadhu <[email protected]>
  • Loading branch information
arghya88 committed Nov 28, 2020
1 parent 4554c7a commit 25f8002
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion pkg/sources/v1alpha2/apiserver_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions pkg/sources/v1alpha2/ping_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 25f8002

Please sign in to comment.