fix: add error message that key pair doesn't exists (#732)
* Add error message that key pair doesn't exists when the API returns a 404 * Update error check
This commit is contained in:
parent
d443b5416d
commit
e989102d6b
1 changed files with 8 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ package keypair
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -130,8 +131,14 @@ func (r *keyPairDataSource) Read(ctx context.Context, req datasource.ReadRequest
|
|||
|
||||
keypairResp, err := r.client.GetKeyPair(ctx, name).Execute()
|
||||
if err != nil {
|
||||
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
if ok && oapiErr.StatusCode == http.StatusNotFound {
|
||||
summary := fmt.Sprintf("Key Pair with name %q does not exists", name)
|
||||
description := fmt.Sprintf("Key Pair with name %q cannot be found. A key pair can be added with the resource \"stackit_key_pair\"", name)
|
||||
diags.AddError(summary, description)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
|
||||
resp.State.RemoveResource(ctx)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue