-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: bo.jiang <bo.jiang@daocloud.io>
- Loading branch information
Showing
14 changed files
with
129 additions
and
69 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
<!-- | ||
Add one of the following kinds: | ||
/kind enhancement | ||
/kind feature | ||
/kind bug | ||
/kind api-change | ||
|
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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
package errors | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
const ( | ||
ErrECSNotFound = "Ecs.0114" | ||
) | ||
|
||
// ECSErrorHandler handles ECS-specific errors. | ||
type ECSErrorHandler struct { | ||
BaseErrorHandler | ||
} | ||
|
||
func (e ECSErrorHandler) IsNotFound(err error) bool { | ||
return e.StatusCode(err) == http.StatusNotFound && e.ErrorCode(err) == ErrECSNotFound | ||
} |
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,23 @@ | ||
package errors | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
const ( | ||
ErrAPINotExist = "APIGW.0101" | ||
ErrELBDataConflict = "ELB.8907" | ||
) | ||
|
||
// ELBErrorHandler handles ELB-specific errors. | ||
type ELBErrorHandler struct { | ||
BaseErrorHandler | ||
} | ||
|
||
func (e ELBErrorHandler) IsNotFound(err error) bool { | ||
return e.StatusCode(err) == http.StatusNotFound && e.ErrorCode(err) == ErrAPINotExist | ||
} | ||
|
||
func (e ELBErrorHandler) IsExists(err error) bool { | ||
return e.StatusCode(err) == http.StatusConflict && e.ErrorCode(err) == ErrELBDataConflict | ||
} |
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,29 @@ | ||
package errors | ||
|
||
import ( | ||
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/sdkerr" | ||
) | ||
|
||
// ErrorHandler defines the interface for handling errors. | ||
type ErrorHandler interface { | ||
StatusCode(err error) int | ||
ErrorCode(err error) string | ||
IsNotFound(err error) bool | ||
} | ||
|
||
// BaseErrorHandler provides common error handling methods. | ||
type BaseErrorHandler struct{} | ||
|
||
func (b BaseErrorHandler) StatusCode(err error) int { | ||
if t, ok := err.(*sdkerr.ServiceResponseError); ok { | ||
return t.StatusCode | ||
} | ||
return -1 | ||
} | ||
|
||
func (b BaseErrorHandler) ErrorCode(err error) string { | ||
if t, ok := err.(*sdkerr.ServiceResponseError); ok { | ||
return t.ErrorCode | ||
} | ||
return "" | ||
} |
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,19 @@ | ||
package errors | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
const ( | ||
ErrVPCNotFound = "VPC.0202" | ||
) | ||
|
||
// VPCErrorHandler handles VPC-specific errors. | ||
type VPCErrorHandler struct { | ||
BaseErrorHandler | ||
} | ||
|
||
func (v VPCErrorHandler) IsNotFound(err error) bool { | ||
statusCode, errorCode := v.StatusCode(err), v.ErrorCode(err) | ||
return (statusCode == http.StatusNotFound || statusCode == http.StatusInternalServerError) && errorCode == ErrVPCNotFound | ||
} |
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
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