improve error handling in clients (#1154)

Signed-off-by: Arghya Sadhu <arghya88@gmail.com>
This commit is contained in:
Arghya Sadhu 2020-11-30 13:55:36 +05:30 committed by GitHub
parent b1fd1875b6
commit 1a57fd8ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -17,6 +17,10 @@
|=== |===
| | Description | PR | | 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 | Add machine readable output (-o flag) to kn source ping describe
| https://github.com/knative/client/pull/1150[#1150] | https://github.com/knative/client/pull/1150[#1150]

View File

@ -104,7 +104,10 @@ func (c *apiServerSourcesClient) UpdateAPIServerSource(apiSource *v1alpha2.ApiSe
//DeleteAPIServerSource is used to create an instance of ApiServerSource //DeleteAPIServerSource is used to create an instance of ApiServerSource
func (c *apiServerSourcesClient) DeleteAPIServerSource(name string) error { func (c *apiServerSourcesClient) DeleteAPIServerSource(name string) error {
err := c.client.Delete(context.TODO(), name, metav1.DeleteOptions{}) 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 // Return the client's namespace

View File

@ -76,16 +76,26 @@ func (c *pingSourcesClient) CreatePingSource(pingsource *v1alpha2.PingSource) er
return fmt.Errorf("a sink is required for creating a source") return fmt.Errorf("a sink is required for creating a source")
} }
_, err := c.client.Create(context.TODO(), pingsource, metav1.CreateOptions{}) _, 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 { func (c *pingSourcesClient) UpdatePingSource(pingSource *v1alpha2.PingSource) error {
_, err := c.client.Update(context.TODO(), pingSource, metav1.UpdateOptions{}) _, 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 { 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) { 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) { func (c *pingSourcesClient) ListPingSource() (*v1alpha2.PingSourceList, error) {
sourceList, err := c.client.List(context.TODO(), metav1.ListOptions{}) sourceList, err := c.client.List(context.TODO(), metav1.ListOptions{})
if err != nil { if err != nil {
return nil, err return nil, knerrors.GetError(err)
} }
return updatePingSourceListGVK(sourceList) return updatePingSourceListGVK(sourceList)