From 7e37a7ec7e91e73fe0d7553b1a1c81cf2efbd001 Mon Sep 17 00:00:00 2001 From: dgupta Date: Thu, 29 Feb 2024 23:50:10 +0530 Subject: [PATCH] moved err check above --- digitalocean/certificate/datasource_certificate.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/digitalocean/certificate/datasource_certificate.go b/digitalocean/certificate/datasource_certificate.go index 50ecbf6ff..7362a6021 100644 --- a/digitalocean/certificate/datasource_certificate.go +++ b/digitalocean/certificate/datasource_certificate.go @@ -95,14 +95,14 @@ func dataSourceDigitalOceanCertificateRead(ctx context.Context, d *schema.Resour func FindCertificateByName(client *godo.Client, name string) (*godo.Certificate, error) { cert, resp, err := client.Certificates.ListByName(context.Background(), name, nil) - if resp != nil && resp.StatusCode == http.StatusNotFound { - return nil, nil - } - if err != nil { return nil, fmt.Errorf("Error retrieving certificates: %s", err) } + if resp != nil && resp.StatusCode == http.StatusNotFound { + return nil, nil + } + if len(cert) == 0 { return nil, fmt.Errorf("certificate not found") }