-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transformation of SQL DB read error so HandleNotFound works (#3396)
- Loading branch information
1 parent
4e82757
commit 77f31fb
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package google | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/errwrap" | ||
"google.golang.org/api/googleapi" | ||
) | ||
|
||
func transformSQLDatabaseReadError(err error) error { | ||
if gErr, ok := errwrap.GetType(err, &googleapi.Error{}).(*googleapi.Error); ok { | ||
if gErr.Code == 400 && strings.Contains(gErr.Message, "Invalid request since instance is not running") { | ||
// This error occurs when attempting a GET after deleting the sql database and sql instance. It leads to to | ||
// inconsistent behavior as handleNotFoundError(...) expects an error code of 404 when a resource does not | ||
// exist. To get the desired behavior from handleNotFoundError, modify the return code to 404 so that | ||
// handleNotFoundError(...) will treat this as a NotFound error | ||
gErr.Code = 404 | ||
} | ||
|
||
log.Printf("[DEBUG] Transformed SQLDatabase error") | ||
return gErr | ||
} | ||
|
||
return err | ||
} |