Skip to content

Commit

Permalink
[chpre] error handler for service maintenace on the top of http client
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Jan 7, 2025
1 parent 23d0a0d commit 50dad3c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions vngcloud/sdk_error/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
)

const (
patternPurchaseIssue = "you do not have sufficient credits to complete the purchase"
patternPagingInvalid = "page or size invalid"
patternTagKeyInvalid = "the value for the tag key contains illegal characters"
patternPurchaseIssue = "you do not have sufficient credits to complete the purchase"
patternPagingInvalid = "page or size invalid"
patternTagKeyInvalid = "the value for the tag key contains illegal characters"
patternServiceMaintenance = "this service is in maintenance"
)

func ErrorHandler(perr error, popts ...func(psdkErr IError)) IError {
Expand All @@ -20,6 +21,14 @@ func ErrorHandler(perr error, popts ...func(psdkErr IError)) IError {
message: "Unknown error",
}

if lstr.Contains(lstr.ToLower(lstr.TrimSpace(perr.Error())), patternServiceMaintenance) {
sdkErr.errorCode = EcServiceMaintenance
sdkErr.message = "Service Maintenance"
sdkErr.error = lfmt.Errorf("service is under maintenance")

return sdkErr
}

for _, opt := range popts {
opt(sdkErr)
if sdkErr.errorCode != EcUnknownError {
Expand Down

0 comments on commit 50dad3c

Please sign in to comment.