File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,37 @@ if err != nil {
5858}
5959```
6060
61+ ### Error handling
62+
63+ All ` Service ` methods return a result and an error object. You can differentiate between generic connection errors
64+ (like the API not being reachable) and service errors, which are errors returned in the response body by the API. This
65+ is useful if you want to gracefully recover from certain types of errors.
66+
67+ ``` go
68+ username := " completely"
69+ password := " invalid"
70+
71+ svc := service.New (client.New (username, password))
72+
73+ _ , err := svc.GetAccount ()
74+
75+ // Handle errors in general
76+ if (err != nil ) {
77+ // Handle service errors specifically
78+ if serviceError , ok := err.(*upcloud.Error ); ok {
79+ fmt.Println (serviceError.ErrorCode )
80+ fmt.Println (serviceError.ErrorMessage )
81+ }
82+ }
83+ ````
84+
85+ This snippet would print the following:
86+
87+ ```
88+ AUTHENTICATION_FAILED
89+ Authentication failed using the given username and password.
90+ ```
91+
6192The rest of these examples assume you already have a service object configured and named `svc`.
6293
6394### Retrieving a list of servers
You can’t perform that action at this time.
0 commit comments