Skip to content

Commit

Permalink
[chore] change the sdkerror into ierror
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Aug 21, 2024
1 parent 731df0a commit be9bf69
Show file tree
Hide file tree
Showing 40 changed files with 276 additions and 276 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func (s *client) VNetworkGateway() lsgateway.IVNetworkGateway {
return s.vnetworkGateway
}

func (s *client) usingIamOauth2AsAuthOption(pauthConfig ISdkConfigure) func() (lsclient.ISdkAuthentication, lserr.ISdkError) {
authFunc := func() (lsclient.ISdkAuthentication, lserr.ISdkError) {
func (s *client) usingIamOauth2AsAuthOption(pauthConfig ISdkConfigure) func() (lsclient.ISdkAuthentication, lserr.IError) {
authFunc := func() (lsclient.ISdkAuthentication, lserr.IError) {
token, err := s.iamGateway.V2().IdentityService().GetAccessToken(
lssvcIdentityV2.NewGetAccessTokenRequest(pauthConfig.GetClientId(), pauthConfig.GetClientSecret()))
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions vngcloud/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (
retryCount int
client *lreq.Client

reauthFunc func() (ISdkAuthentication, lserr.ISdkError)
reauthFunc func() (ISdkAuthentication, lserr.IError)
reauthOption AuthOpts

accessToken ISdkAuthentication
Expand All @@ -39,7 +39,7 @@ type (

reauthFuture struct {
done chan struct{}
err lserr.ISdkError
err lserr.IError
}

AuthOpts string
Expand Down Expand Up @@ -89,13 +89,13 @@ func (s *httpClient) WithKvDefaultHeaders(pargs ...string) IHttpClient {
return s
}

func (s *httpClient) WithReauthFunc(pauthOpt AuthOpts, preauthFunc func() (ISdkAuthentication, lserr.ISdkError)) IHttpClient {
func (s *httpClient) WithReauthFunc(pauthOpt AuthOpts, preauthFunc func() (ISdkAuthentication, lserr.IError)) IHttpClient {
s.reauthFunc = preauthFunc
s.reauthOption = pauthOpt
return s
}

func (s *httpClient) DoRequest(purl string, preq IRequest) (*lreq.Response, lserr.ISdkError) {
func (s *httpClient) DoRequest(purl string, preq IRequest) (*lreq.Response, lserr.IError) {
req := s.client.R().SetContext(s.context).SetHeaders(s.defaultHeaders).SetHeaders(preq.GetMoreHeaders())
if opt := preq.GetRequestBody(); opt != nil {
req.SetBodyJsonMarshal(opt)
Expand Down Expand Up @@ -172,7 +172,7 @@ func (s *httpClient) needReauth(preq IRequest) bool {
return s.accessToken.NeedReauth()
}

func (s *httpClient) reauthenticate() lserr.ISdkError {
func (s *httpClient) reauthenticate() lserr.IError {
if s.reauthFunc == nil {
return lserr.ErrorHandler(nil, lserr.WithErrorReauthFuncNotSet())
}
Expand Down Expand Up @@ -217,17 +217,17 @@ func newReauthFuture() *reauthFuture {
}
}

func (s *reauthFuture) get() lserr.ISdkError {
func (s *reauthFuture) get() lserr.IError {
<-s.done
return s.err
}

func (s *reauthFuture) set(err lserr.ISdkError) {
func (s *reauthFuture) set(err lserr.IError) {
s.err = err
close(s.done)
}

func defaultErrorResponse(perr error, purl string, preq IRequest, resp *lreq.Response) lserr.ISdkError {
func defaultErrorResponse(perr error, purl string, preq IRequest, resp *lreq.Response) lserr.IError {
return lserr.ErrorHandler(perr).WithKVparameters(
"statusCode", resp.StatusCode,
"url", purl,
Expand Down
4 changes: 2 additions & 2 deletions vngcloud/client/iclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type IHttpClient interface {
WithTimeout(ptimeout ltime.Duration) IHttpClient
WithSleep(psleep ltime.Duration) IHttpClient
WithKvDefaultHeaders(pargs ...string) IHttpClient
WithReauthFunc(pauthOpt AuthOpts, preauthFunc func() (ISdkAuthentication, lserr.ISdkError)) IHttpClient
WithReauthFunc(pauthOpt AuthOpts, preauthFunc func() (ISdkAuthentication, lserr.IError)) IHttpClient

DoRequest(purl string, preq IRequest) (*lreq.Response, lserr.ISdkError)
DoRequest(purl string, preq IRequest) (*lreq.Response, lserr.IError)
}

type IRequest interface {
Expand Down
8 changes: 4 additions & 4 deletions vngcloud/client/iservice_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type IServiceClient interface {
GetZoneId() string
GetUserId() string

Post(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError)
Get(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError)
Delete(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError)
Put(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError)
Post(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError)
Get(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError)
Delete(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError)
Put(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError)
}

type ISdkAuthentication interface {
Expand Down
8 changes: 4 additions & 4 deletions vngcloud/client/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ func (s *serviceClient) ServiceURL(pparts ...string) string {
return s.endpoint + lstr.Join(pparts, "/")
}

func (s *serviceClient) Post(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError) {
func (s *serviceClient) Post(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError) {
return s.client.DoRequest(purl, preq.WithRequestMethod(MethodPost))
}

func (s *serviceClient) Get(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError) {
func (s *serviceClient) Get(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError) {
return s.client.DoRequest(purl, preq.WithRequestMethod(MethodGet))
}

func (s *serviceClient) Delete(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError) {
func (s *serviceClient) Delete(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError) {
return s.client.DoRequest(purl, preq.WithRequestMethod(MethodDelete))
}

func (s *serviceClient) Put(purl string, preq IRequest) (*lreq.Response, lsdkErr.ISdkError) {
func (s *serviceClient) Put(purl string, preq IRequest) (*lreq.Response, lsdkErr.IError) {
return s.client.DoRequest(purl, preq.WithRequestMethod(MethodPut))
}

Expand Down
24 changes: 12 additions & 12 deletions vngcloud/sdk_error/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
patternPagingInvalid = "page or size invalid"
)

func ErrorHandler(perr error, popts ...func(psdkErr ISdkError)) ISdkError {
func ErrorHandler(perr error, popts ...func(psdkErr IError)) IError {
sdkErr := &SdkError{
error: perr,
errorCode: EcUnknownError,
Expand All @@ -30,7 +30,7 @@ func ErrorHandler(perr error, popts ...func(psdkErr ISdkError)) ISdkError {
return sdkErr
}

func SdkErrorHandler(psdkErr ISdkError, perrResp IErrorRespone, popts ...func(psdkErr ISdkError)) ISdkError {
func SdkErrorHandler(psdkErr IError, perrResp IErrorRespone, popts ...func(psdkErr IError)) IError {
if psdkErr == nil && perrResp == nil {
return nil
}
Expand All @@ -54,24 +54,24 @@ func SdkErrorHandler(psdkErr ISdkError, perrResp IErrorRespone, popts ...func(ps
return psdkErr
}

func WithErrorInternalServerError() func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorInternalServerError() func(IError) {
return func(sdkErr IError) {
sdkErr.WithErrorCode(EcInternalServerError).
WithMessage("Internal Server Error").
WithErrors(lfmt.Errorf("internal server error from making request to external service"))
}
}

func WithErrorPermissionDenied() func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorPermissionDenied() func(IError) {
return func(sdkErr IError) {
sdkErr.WithErrorCode(EcPermissionDenied).
WithMessage("Permission Denied").
WithErrors(lfmt.Errorf("permission denied when making request to external service"))
}
}

func WithErrorOutOfPoc(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorOutOfPoc(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand All @@ -85,8 +85,8 @@ func WithErrorOutOfPoc(perrResp IErrorRespone) func(sdkError ISdkError) {
}
}

func WithErrorPagingInvalid(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorPagingInvalid(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand All @@ -100,8 +100,8 @@ func WithErrorPagingInvalid(perrResp IErrorRespone) func(sdkError ISdkError) {
}
}

func WithErrorUnexpected() func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorUnexpected() func(IError) {
return func(sdkErr IError) {
sdkErr.WithErrorCode(EcUnexpectedError).
WithMessage("Unexpected Error").
WithErrors(lfmt.Errorf("unexpected error from making request to external service"))
Expand Down
20 changes: 10 additions & 10 deletions vngcloud/sdk_error/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package sdk_error

import lstr "strings"

func WithErrorEndpointStatusInvalid(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorEndpointStatusInvalid(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand All @@ -16,8 +16,8 @@ func WithErrorEndpointStatusInvalid(perrResp IErrorRespone) func(sdkError ISdkEr
}
}

func WithErrorEndpointOfVpcExists(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorEndpointOfVpcExists(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand All @@ -30,8 +30,8 @@ func WithErrorEndpointOfVpcExists(perrResp IErrorRespone) func(sdkError ISdkErro
}
}

func WithErrorEndpointPackageNotBelongToEndpointService(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorEndpointPackageNotBelongToEndpointService(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand All @@ -44,8 +44,8 @@ func WithErrorEndpointPackageNotBelongToEndpointService(perrResp IErrorRespone)
}
}

func WithErrorContainInvalidCharacter(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorContainInvalidCharacter(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand All @@ -58,8 +58,8 @@ func WithErrorContainInvalidCharacter(perrResp IErrorRespone) func(sdkError ISdk
}
}

func WithErrorLockOnProcess(perrResp IErrorRespone) func(sdkError ISdkError) {
return func(sdkError ISdkError) {
func WithErrorLockOnProcess(perrResp IErrorRespone) func(sdkError IError) {
return func(sdkError IError) {
if perrResp == nil {
return
}
Expand Down
16 changes: 8 additions & 8 deletions vngcloud/sdk_error/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
lfmt "fmt"
)

func WithErrorAuthenticationFailed(perrResp IErrorRespone) func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorAuthenticationFailed(perrResp IErrorRespone) func(IError) {
return func(sdkErr IError) {
if perrResp == nil {
return
}
Expand All @@ -22,16 +22,16 @@ func WithErrorAuthenticationFailed(perrResp IErrorRespone) func(ISdkError) {
}
}

func WithErrorReauthFuncNotSet() func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorReauthFuncNotSet() func(IError) {
return func(sdkErr IError) {
sdkErr.WithErrorCode(EcReauthFuncNotSet).
WithMessage("Reauthentication function is not configured").
WithErrors(lfmt.Errorf("reauthentication function is not configured"))
}
}

func WithErrorTooManyFailedLogin(perrResp IErrorRespone) func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorTooManyFailedLogin(perrResp IErrorRespone) func(IError) {
return func(sdkErr IError) {
if perrResp == nil {
return
}
Expand All @@ -48,8 +48,8 @@ func WithErrorTooManyFailedLogin(perrResp IErrorRespone) func(ISdkError) {
}
}

func WithErrorUnknownAuthFailure(perrResp IErrorRespone) func(ISdkError) {
return func(sdkErr ISdkError) {
func WithErrorUnknownAuthFailure(perrResp IErrorRespone) func(IError) {
return func(sdkErr IError) {
if perrResp == nil {
return
}
Expand Down
12 changes: 6 additions & 6 deletions vngcloud/sdk_error/isdk_error.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package sdk_error

type ISdkError interface {
type IError interface {
IsError(perrCode ErrorCode) bool
IsErrorAny(perrCodes ...ErrorCode) bool

WithErrorCode(perrCode ErrorCode) ISdkError
WithMessage(pmsg string) ISdkError
WithErrors(perrs ...error) ISdkError
WithParameters(pparams map[string]interface{}) ISdkError
WithKVparameters(pparams ...interface{}) ISdkError
WithErrorCode(perrCode ErrorCode) IError
WithMessage(pmsg string) IError
WithErrors(perrs ...error) IError
WithParameters(pparams map[string]interface{}) IError
WithKVparameters(pparams ...interface{}) IError

GetError() error
GetMessage() string
Expand Down
Loading

0 comments on commit be9bf69

Please sign in to comment.