From c25fc63418fe3e880e3750bd2b1896fa37b4691a Mon Sep 17 00:00:00 2001 From: Ciprian Tibulca Date: Mon, 19 Feb 2024 09:35:20 +0000 Subject: [PATCH] Update docs with example of handling HTTP response status codes (#278) --- docs/doc_2_error_handling.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/doc_2_error_handling.md b/docs/doc_2_error_handling.md index 19bfccd7e..c1a34b784 100644 --- a/docs/doc_2_error_handling.md +++ b/docs/doc_2_error_handling.md @@ -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/). @@ -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" @@ -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 +} +```