Updated error handling example based on PR feedback

This commit is contained in:
Marc Sluiter 2017-05-29 23:21:23 +02:00
parent 8ca1732023
commit 601ab10dbd
2 changed files with 12 additions and 4 deletions

View File

@ -45,10 +45,14 @@ func main() {
}
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
// Example for handling status errors
// Examples for error handling:
// - Use helper functions like e.g. errors.IsNotFound()
// - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
_, err = clientset.CoreV1().Pods("").Get("ExamplePodName", metav1.GetOptions{})
if statusError, isStatus := err.(*errors.StatusError); isStatus && statusError.Status().Reason == metav1.StatusReasonNotFound {
if errors.IsNotFound(err) {
fmt.Printf("Pod not found\n")
} else if statusError, isStatus := err.(*errors.StatusError); isStatus {
fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message)
} else if err != nil {
panic(err.Error())
} else {

View File

@ -59,10 +59,14 @@ func main() {
}
fmt.Printf("There are %d pods in the cluster\n", len(pods.Items))
// Example for handling status errors
// Examples for error handling:
// - Use helper functions like e.g. errors.IsNotFound()
// - And/or cast to StatusError and use its properties like e.g. ErrStatus.Message
_, err = clientset.CoreV1().Pods("").Get("ExamplePodName", metav1.GetOptions{})
if statusError, isStatus := err.(*errors.StatusError); isStatus && statusError.Status().Reason == metav1.StatusReasonNotFound {
if errors.IsNotFound(err) {
fmt.Printf("Pod not found\n")
} else if statusError, isStatus := err.(*errors.StatusError); isStatus {
fmt.Printf("Error getting pod %v\n", statusError.ErrStatus.Message)
} else if err != nil {
panic(err.Error())
} else {