fix status codes on certain http error codes and re-enable two tests

This commit is contained in:
Danielle Miu committed 2024-07-17 10:54:21 -04:00
1 parent 08d1e99e8b
commit be5cb745ab
2 files changed
+22 -58

No files matched your search

+5 -20
View File
@@ -110,22 +110,6 @@ func ParseAWSError(err error, msg string) (st *status.Status, permission *pb.Per
statusMsg := fmt.Sprintf("aws service %s: throttling error: %s", serviceName, msg) statusMsg := fmt.Sprintf("aws service %s: throttling error: %s", serviceName, msg)
return status.New(codes.Unavailable, statusMsg), nil return status.New(codes.Unavailable, statusMsg), nil
} }
// evaluate against aws connection error codes
connectionErr := retry.IsErrorRetryables([]retry.IsErrorRetryable{
retry.NoRetryCanceledError{},
retry.RetryableError{},
retry.RetryableConnectionError{},
retry.RetryableHTTPStatusCode{
Codes: retry.DefaultRetryableHTTPStatusCodes,
},
retry.RetryableErrorCode{
Codes: retry.DefaultRetryableErrorCodes,
},
})
if connectionErr.IsErrorRetryable(err).Bool() {
statusMsg := fmt.Sprintf("aws service %s: connectivity error: %s", serviceName, msg)
return status.New(codes.DeadlineExceeded, statusMsg), nil
}
// parse some specific aws error codes that we have special cred states for // parse some specific aws error codes that we have special cred states for
var apiErr smithy.APIError var apiErr smithy.APIError
@@ -192,16 +176,17 @@ func ParseAWSError(err error, msg string) (st *status.Status, permission *pb.Per
case http.StatusTooManyRequests: case http.StatusTooManyRequests:
statusMsg := fmt.Sprintf("aws service %s: throttling error: %s", serviceName, msg) statusMsg := fmt.Sprintf("aws service %s: throttling error: %s", serviceName, msg)
return status.New(codes.Unavailable, statusMsg), nil return status.New(codes.Unavailable, statusMsg), nil
case http.StatusRequestTimeout:
fallthrough
case http.StatusInternalServerError: case http.StatusInternalServerError:
fallthrough fallthrough
case http.StatusBadGateway: case http.StatusBadGateway:
fallthrough fallthrough
case http.StatusServiceUnavailable: case http.StatusServiceUnavailable:
statusMsg := fmt.Sprintf("aws service %s: connectivity error: %s", serviceName, msg)
return status.New(codes.Unavailable, statusMsg), nil
case http.StatusRequestTimeout:
fallthrough fallthrough
case http.StatusGatewayTimeout: case http.StatusGatewayTimeout:
statusMsg := fmt.Sprintf("aws service %s: connectivity error: %s", serviceName, msg) statusMsg := fmt.Sprintf("aws service %s: timeout error: %s", serviceName, msg)
return status.New(codes.DeadlineExceeded, statusMsg), nil return status.New(codes.DeadlineExceeded, statusMsg), nil
} }
} }
@@ -216,7 +201,7 @@ func BadRequestStatus(format string, args ...any) error {
} }
// UnknownStatus returns a status error with an internal // UnknownStatus returns a status error with an internal
// error code and a retryable plugin error detail. // error code
func UnknownStatus(format string, args ...any) error { func UnknownStatus(format string, args ...any) error {
return status.New(codes.Internal, fmt.Sprintf(format, args...)).Err() return status.New(codes.Internal, fmt.Sprintf(format, args...)).Err()
} }
+17 -38
View File
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
) )
@@ -326,42 +327,20 @@ func Test_ParseAWSError(t *testing.T) {
} }
} }
// func Test_BadRequestStatus(t *testing.T) { func Test_BadRequestStatus(t *testing.T) {
// require, assert := require.New(t), assert.New(t) require, assert := require.New(t), assert.New(t)
// err := BadRequestStatus("test: %s", "hello world") err := BadRequestStatus("test: %s", "hello world")
// assert.ErrorContains(err, "test: hello world") assert.ErrorContains(err, "test: hello world")
// assert.Equal(status.Code(err), codes.InvalidArgument) assert.Equal(status.Code(err), codes.InvalidArgument)
// st, ok := status.FromError(err) _, ok := status.FromError(err)
// require.True(ok) require.True(ok)
// var plgErr *pb.PluginError }
// for _, detail := range st.Details() {
// if errDetail, ok := detail.(*pb.PluginError); ok {
// plgErr = errDetail
// break
// }
// }
// require.NotNil(plgErr)
// assert.Equal(pb.ERROR_ERROR_BAD_REQUEST, plgErr.Code)
// assert.Equal("bad request", plgErr.Message)
// assert.True(plgErr.Nonretryable)
// }
// func Test_UnknownStatus(t *testing.T) { func Test_UnknownStatus(t *testing.T) {
// require, assert := require.New(t), assert.New(t) require, assert := require.New(t), assert.New(t)
// err := UnknownStatus("test: %s", "hello world") err := UnknownStatus("test: %s", "hello world")
// assert.ErrorContains(err, "test: hello world") assert.ErrorContains(err, "test: hello world")
// assert.Equal(status.Code(err), codes.Internal) assert.Equal(status.Code(err), codes.Internal)
// st, ok := status.FromError(err) _, ok := status.FromError(err)
// require.True(ok) require.True(ok)
// var plgErr *pb.PluginError }
// for _, detail := range st.Details() {
// if errDetail, ok := detail.(*pb.PluginError); ok {
// plgErr = errDetail
// break
// }
// }
// require.NotNil(plgErr)
// assert.Equal(pb.ERROR_ERROR_UNKNOWN, plgErr.Code)
// assert.Equal("unknown internal error", plgErr.Message)
// assert.False(plgErr.Nonretryable)
// }