Skip to content

Commit 43f5492

Browse files
authored
chore: Fix error code mapping (#1571)
1 parent 84cda07 commit 43f5492

2 files changed

Lines changed: 5 additions & 31 deletions

File tree

cfn-resources/util/cluster_common.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ func HandleClusterError(err error, resp *http.Response) *handler.ProgressEvent {
3333
if resp != nil && resp.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), constants.Duplicate) {
3434
pe.HandlerErrorCode = string(types.HandlerErrorCodeAlreadyExists)
3535
}
36-
if resp != nil && resp.StatusCode == http.StatusNotFound {
37-
pe.HandlerErrorCode = string(types.HandlerErrorCodeNotFound)
38-
}
3936
if strings.Contains(err.Error(), "not exist") || strings.Contains(err.Error(), "being deleted") {
4037
pe.HandlerErrorCode = string(types.HandlerErrorCodeNotFound)
4138
}

cfn-resources/util/progressevent/failed_event.go

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ import (
2222
)
2323

2424
func getHandlerErrorCode(response *http.Response) string {
25+
if response == nil {
26+
return string(types.HandlerErrorCodeInternalFailure)
27+
}
2528
switch response.StatusCode {
2629
case http.StatusBadRequest:
2730
return string(types.HandlerErrorCodeInvalidRequest)
2831
case http.StatusNotFound:
2932
return string(types.HandlerErrorCodeNotFound)
33+
case http.StatusConflict:
34+
return string(types.HandlerErrorCodeAlreadyExists)
3035
case http.StatusInternalServerError:
3136
return string(types.HandlerErrorCodeServiceInternalError)
3237
case http.StatusPaymentRequired, http.StatusUnauthorized:
@@ -37,34 +42,6 @@ func getHandlerErrorCode(response *http.Response) string {
3742
}
3843

3944
func GetFailedEventByResponse(message string, response *http.Response) handler.ProgressEvent {
40-
if response == nil {
41-
return handler.ProgressEvent{
42-
OperationStatus: handler.Failed,
43-
Message: message,
44-
HandlerErrorCode: string(types.HandlerErrorCodeHandlerInternalFailure)}
45-
}
46-
47-
if response.StatusCode == http.StatusConflict {
48-
return handler.ProgressEvent{
49-
OperationStatus: handler.Failed,
50-
Message: message,
51-
HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}
52-
}
53-
54-
if response.StatusCode == http.StatusUnauthorized {
55-
return handler.ProgressEvent{
56-
OperationStatus: handler.Failed,
57-
Message: "Not found",
58-
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}
59-
}
60-
61-
if response.StatusCode == http.StatusBadRequest {
62-
return handler.ProgressEvent{
63-
OperationStatus: handler.Failed,
64-
Message: message,
65-
HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}
66-
}
67-
6845
return handler.ProgressEvent{
6946
OperationStatus: handler.Failed,
7047
Message: message,

0 commit comments

Comments
 (0)