Skip to content

Commit

Permalink
Added Error.IsRetryable() and StatusResourceExhausted (#56)
Browse files Browse the repository at this point in the history
The Error.IsRetryable(...) will tell the user whether retrying this error might resolve the issue.

`StatusResourceExhausted` error will be retruned when a user sends more requests that is allowed by their quota.
  • Loading branch information
stepanbujnak authored Oct 27, 2024
1 parent ed07b33 commit e34d3c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 000init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package pex
// #cgo LDFLAGS: -Wl,-rpath,/usr/local/lib
//
// #define PEX_SDK_MAJOR_VERSION 4
// #define PEX_SDK_MINOR_VERSION 4
// #define PEX_SDK_MINOR_VERSION 5
//
// #include <pex/sdk/version.h>
import "C"
Expand Down
35 changes: 19 additions & 16 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ import "fmt"
type StatusCode int

const (
StatusOK = StatusCode(0)
StatusDeadlineExceeded = StatusCode(1)
StatusPermissionDenied = StatusCode(2)
StatusUnauthenticated = StatusCode(3)
StatusNotFound = StatusCode(4)
StatusInvalidInput = StatusCode(5)
StatusOutOfMemory = StatusCode(6)
StatusInternalError = StatusCode(7)
StatusNotInitialized = StatusCode(8)
StatusConnectionError = StatusCode(9)
StatusLookupFailed = StatusCode(10)
StatusLookupTimedOut = StatusCode(11)
StatusOK = StatusCode(0)
StatusDeadlineExceeded = StatusCode(1)
StatusPermissionDenied = StatusCode(2)
StatusUnauthenticated = StatusCode(3)
StatusNotFound = StatusCode(4)
StatusInvalidInput = StatusCode(5)
StatusOutOfMemory = StatusCode(6)
StatusInternalError = StatusCode(7)
StatusNotInitialized = StatusCode(8)
StatusConnectionError = StatusCode(9)
StatusLookupFailed = StatusCode(10)
StatusLookupTimedOut = StatusCode(11)
StatusResourceExhausted = StatusCode(12)
)

// Error will be returend by most SDK functions. Besides an error
// message, it also includes a status code, which can be used to
// determine the underlying issue, e.g. AssetLibrary.GetAsset will return
// an error with StatusNotFound if the asset couldn't be found.
type Error struct {
Code StatusCode
Message string
Code StatusCode
Message string
IsRetryable bool
}

func (e *Error) Error() string {
Expand All @@ -41,8 +43,9 @@ func (e *Error) Error() string {
func statusToError(status *C.Pex_Status) error {
if !C.Pex_Status_OK(status) {
return &Error{
Code: StatusCode(C.Pex_Status_GetCode(status)),
Message: C.GoString(C.Pex_Status_GetMessage(status)),
Code: StatusCode(C.Pex_Status_GetCode(status)),
Message: C.GoString(C.Pex_Status_GetMessage(status)),
IsRetryable: bool(C.Pex_Status_IsRetryable(status)),
}
}
return nil
Expand Down

0 comments on commit e34d3c7

Please sign in to comment.