Skip to content

Commit

Permalink
[enhance] add service maintenance when calling api
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongpiger committed Aug 26, 2024
1 parent 24b87df commit d3dd267
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vngcloud/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ func (s *httpClient) DoRequest(purl string, preq IRequest) (*lreq.Response, lser
return nil, lserr.SdkErrorHandler(
defaultErrorResponse(resp.Err, purl, preq, resp), nil,
lserr.WithErrorInternalServerError())
case lhttp.StatusServiceUnavailable:
return nil, lserr.SdkErrorHandler(
defaultErrorResponse(resp.Err, purl, preq, resp), nil,
lserr.WithErrorServiceMaintenance())
case lhttp.StatusForbidden:
return nil, lserr.SdkErrorHandler(
defaultErrorResponse(resp.Err, purl, preq, resp), nil,
Expand Down
8 changes: 8 additions & 0 deletions vngcloud/sdk_error/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func WithErrorInternalServerError() func(IError) {
}
}

func WithErrorServiceMaintenance() func(IError) {
return func(sdkErr IError) {
sdkErr.WithErrorCode(EcServiceMaintenance).
WithMessage("Service Maintenance").
WithErrors(lfmt.Errorf("service is under maintenance"))
}
}

func WithErrorPermissionDenied() func(IError) {
return func(sdkErr IError) {
sdkErr.WithErrorCode(EcPermissionDenied).
Expand Down
1 change: 1 addition & 0 deletions vngcloud/sdk_error/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (
EcUnknownError = ErrorCode("UnknownError")

EcInternalServerError = ErrorCode("VngCloudApiInternalServerError")
EcServiceMaintenance = ErrorCode("VngCloudServiceMaintenance")
EcPagingInvalid = ErrorCode("VngCloudApiPagingInvalid")
EcPermissionDenied = ErrorCode("VngCloudApiPermissionDenied")
EcUnexpectedError = ErrorCode("VngCloudApiUnexpectedError")
Expand Down

0 comments on commit d3dd267

Please sign in to comment.