-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
100 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package errors | ||
|
||
import ( | ||
lssdkErr "github.com/vngcloud/vngcloud-go-sdk/error" | ||
lstr "strings" | ||
) | ||
|
||
const ( | ||
patternSecgroupNameAlreadyExists = "name of security group already exist" | ||
patternSecgroupExceedQuota = "exceeded secgroup quota" | ||
patternSecgroupInUse = "securitygroupinuse" | ||
patternSecgroupNotFound = "cannot get security group with id" | ||
) | ||
|
||
var ( | ||
ErrCodeSecgroupNameAlreadyExists lssdkErr.ErrorCode = "ErrorSecgroupNameAlreadyExists" | ||
ErrCodeSecgroupExceedQuota lssdkErr.ErrorCode = "ErrorSecgroupExceedQuota" | ||
ErrCodeSecgroupInUse lssdkErr.ErrorCode = "ErrorSecgroupInUse" | ||
ErrCodeSecgroupNotFound lssdkErr.ErrorCode = "ErrorSecgroupNotFound" | ||
) | ||
|
||
func WithErrorSecgroupNameAlreadyExists(perrResp *lssdkErr.ErrorResponse, perr error) func(*lssdkErr.SdkError) { | ||
return func(sdkError *lssdkErr.SdkError) { | ||
if perrResp == nil { | ||
return | ||
} | ||
|
||
errMsg := perrResp.Message | ||
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternSecgroupNameAlreadyExists) { | ||
sdkError.Code = ErrCodeSecgroupNameAlreadyExists | ||
sdkError.Message = errMsg | ||
sdkError.Error = perr | ||
} | ||
} | ||
} | ||
|
||
func WithErrorSecgroupExceedQuota(perrResp *lssdkErr.ErrorResponse, perr error) func(*lssdkErr.SdkError) { | ||
return func(sdkError *lssdkErr.SdkError) { | ||
if perrResp == nil { | ||
return | ||
} | ||
|
||
errMsg := perrResp.Message | ||
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternSecgroupExceedQuota) { | ||
sdkError.Code = ErrCodeSecgroupExceedQuota | ||
sdkError.Message = errMsg | ||
sdkError.Error = perr | ||
} | ||
} | ||
} | ||
|
||
func WithErrorSecgroupInUse(perrResp *lssdkErr.ErrorResponse, perr error) func(*lssdkErr.SdkError) { | ||
return func(sdkError *lssdkErr.SdkError) { | ||
if perrResp == nil { | ||
return | ||
} | ||
|
||
errMsg := perrResp.Message | ||
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternSecgroupInUse) { | ||
sdkError.Code = ErrCodeSecgroupInUse | ||
sdkError.Message = errMsg | ||
sdkError.Error = perr | ||
} | ||
} | ||
} | ||
|
||
func WithErrorSecgroupNotFound(perrResp *lssdkErr.ErrorResponse, perr error) func(*lssdkErr.SdkError) { | ||
return func(sdkError *lssdkErr.SdkError) { | ||
if perrResp == nil { | ||
return | ||
} | ||
|
||
errMsg := perrResp.Message | ||
if lstr.Contains(lstr.ToLower(lstr.TrimSpace(errMsg)), patternSecgroupNotFound) { | ||
sdkError.Code = ErrCodeSecgroupNotFound | ||
sdkError.Message = errMsg | ||
sdkError.Error = perr | ||
} | ||
} | ||
} |
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