Skip to content

What's the best way to handle not found error? #1110

@csandanov

Description

@csandanov

I found the following example in CHANGELOG:

// To get a specific API error
var notFoundErr *types.ResourceNotFoundException
if errors.As(err, &notFoundErr) {
    log.Printf("scan failed because the table was not found, %v", notFoundErr.ErrorMessage())
}

So I tried this with RDS:

_, err := client.DescribeDBInstances(ctx, &rds.DescribeDBInstancesInput{
    DBInstanceIdentifier: aws.String(identifier),
})
if err != nil {
    var notFoundErr *types.DBInstanceNotFoundFault
    // Doesn't work.
    // I also tried using types.ResourceNotFoundFault.
    if errors.As(err, &notFoundErr) {
         // 
    }
}

This works:

var apiErr smithy.APIError
if errors.As(err, &apiErr) {
     //
}

Does this work as intended? Should I get 404 from response status code if I want to identify not found error?

Metadata

Metadata

Assignees

Labels

closed-for-stalenessguidanceQuestion that needs advice or information.response-requestedWaiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions