fix status codes on certain http error codes and re-enable two tests
This commit is contained in:
1 parent
08d1e99e8b
commit
be5cb745ab
2 files changed
+22
-58
No files matched your search
@@ -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)
|
||||
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
|
||||
var apiErr smithy.APIError
|
||||
@@ -192,16 +176,17 @@ func ParseAWSError(err error, msg string) (st *status.Status, permission *pb.Per
|
||||
case http.StatusTooManyRequests:
|
||||
statusMsg := fmt.Sprintf("aws service %s: throttling error: %s", serviceName, msg)
|
||||
return status.New(codes.Unavailable, statusMsg), nil
|
||||
case http.StatusRequestTimeout:
|
||||
fallthrough
|
||||
case http.StatusInternalServerError:
|
||||
fallthrough
|
||||
case http.StatusBadGateway:
|
||||
fallthrough
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -216,7 +201,7 @@ func BadRequestStatus(format string, args ...any) error {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return status.New(codes.Internal, fmt.Sprintf(format, args...)).Err()
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
@@ -326,42 +327,20 @@ func Test_ParseAWSError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// func Test_BadRequestStatus(t *testing.T) {
|
||||
// require, assert := require.New(t), assert.New(t)
|
||||
// err := BadRequestStatus("test: %s", "hello world")
|
||||
// assert.ErrorContains(err, "test: hello world")
|
||||
// assert.Equal(status.Code(err), codes.InvalidArgument)
|
||||
// st, ok := status.FromError(err)
|
||||
// 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_BadRequestStatus(t *testing.T) {
|
||||
require, assert := require.New(t), assert.New(t)
|
||||
err := BadRequestStatus("test: %s", "hello world")
|
||||
assert.ErrorContains(err, "test: hello world")
|
||||
assert.Equal(status.Code(err), codes.InvalidArgument)
|
||||
_, ok := status.FromError(err)
|
||||
require.True(ok)
|
||||
}
|
||||
|
||||
// func Test_UnknownStatus(t *testing.T) {
|
||||
// require, assert := require.New(t), assert.New(t)
|
||||
// err := UnknownStatus("test: %s", "hello world")
|
||||
// assert.ErrorContains(err, "test: hello world")
|
||||
// assert.Equal(status.Code(err), codes.Internal)
|
||||
// st, ok := status.FromError(err)
|
||||
// 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)
|
||||
// }
|
||||
func Test_UnknownStatus(t *testing.T) {
|
||||
require, assert := require.New(t), assert.New(t)
|
||||
err := UnknownStatus("test: %s", "hello world")
|
||||
assert.ErrorContains(err, "test: hello world")
|
||||
assert.Equal(status.Code(err), codes.Internal)
|
||||
_, ok := status.FromError(err)
|
||||
require.True(ok)
|
||||
}
|
||||
Reference in new issue
Block a user