Docs Menu
Docs Home
/
MongoDB Atlas
/ / /

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.

Errors are represented by ApiErrorObject.

To fetch the error object, execute the following:

import "go.mongodb.org/atlas-sdk/v20231115014/admin"
projects, response, err := admin.ProjectsApi.ListProjects(ctx).Execute()
apiError, ok := admin.AsError(err)
fmt.Println(apiError)

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

import admin "go.mongodb.org/atlas-sdk/v20231115014/admin"
projects, response, err := admin.ProjectsApi.ListProjects(ctx).Execute()
if admin.IsErrorCode(err, "code"){
// Do something
}

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

import admin "go.mongodb.org/atlas-sdk/v20231115014/admin"
projects, response, err := admin.ProjectsApi.ListProjects(ctx).Execute()
apiError, ok := admin.AsError(err)
if ok && apiError.GetError() == 404 {
// Do something
}
← Learn Concepts for the Atlas Go SDK