Skip to content

Commit

Permalink
Update docs with example of handling HTTP response status codes (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibulca authored Feb 19, 2024
1 parent 0578926 commit c25fc63
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/doc_2_error_handling.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Error Handling

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/).
Expand All @@ -19,7 +18,7 @@ fmt.Println(apiError)

## Checking for the Existence of a Specific Error Code

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

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

## Checking for the Existence of a Specific Response Status Code

To check for the existence of a specific HTTP response error code, execute the following:

```go
import admin "go.mongodb.org/atlas-sdk/v20231115007/admin"

projects, response, err := admin.ProjectsApi.ListProjects(ctx).Execute()
apiError, ok := admin.AsError(err)
if ok && apiError.GetError() == 404 {
// Do something
}
```

0 comments on commit c25fc63

Please sign in to comment.