Skip to content

Commit c25fc63

Browse files
Update docs with example of handling HTTP response status codes (#278)
1 parent 0578926 commit c25fc63

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

docs/doc_2_error_handling.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Error Handling
32

43
You can obtain detailed information about errors returned by the API when you use the Atlas Go SDK. Use the error code to determine the cause of the error. To learn more about API error codes, see [Atlas Administration API Error Codes](https://www.mongodb.com/docs/atlas/reference/api-errors/).
@@ -19,7 +18,7 @@ fmt.Println(apiError)
1918

2019
## Checking for the Existence of a Specific Error Code
2120

22-
To check for the existence of a specific error code, execute the following:
21+
To check for the existence of a specific error code (e.g. `MAXIMUM_INDEXES_FOR_TENANT_EXCEEDED`), execute the following:
2322

2423
```go
2524
import admin "go.mongodb.org/atlas-sdk/v20231115007/admin"
@@ -30,3 +29,16 @@ if admin.IsErrorCode(err, "code"){
3029
}
3130
```
3231

32+
## Checking for the Existence of a Specific Response Status Code
33+
34+
To check for the existence of a specific HTTP response error code, execute the following:
35+
36+
```go
37+
import admin "go.mongodb.org/atlas-sdk/v20231115007/admin"
38+
39+
projects, response, err := admin.ProjectsApi.ListProjects(ctx).Execute()
40+
apiError, ok := admin.AsError(err)
41+
if ok && apiError.GetError() == 404 {
42+
// Do something
43+
}
44+
```

0 commit comments

Comments
 (0)