Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package commerce
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
ErrorCodeUnauthorized = "unauthorized"
|
|
ErrorCodeTimeout = "timeout"
|
|
ErrorCodeUnavailable = "unavailable"
|
|
)
|
|
|
|
var (
|
|
ErrBaseURLRequired = errors.New("commerce base URL is required")
|
|
ErrRequestAuthorizerRequired = errors.New("commerce request authorizer is required")
|
|
ErrRewardReceiptStoreRequired = errors.New("commerce reward receipt store is required")
|
|
ErrRegistrationCreditsRewardIDRequired = errors.New("registration credits reward id is required")
|
|
)
|
|
|
|
type HTTPError struct {
|
|
StatusCode int
|
|
}
|
|
|
|
func (e *HTTPError) Error() string {
|
|
return fmt.Sprintf("commerce request failed with status %d", e.StatusCode)
|
|
}
|
|
|
|
func ErrorCode(err error) string {
|
|
if err == nil {
|
|
return ""
|
|
}
|
|
var httpError *HTTPError
|
|
if errors.As(err, &httpError) {
|
|
if httpError.StatusCode == http.StatusUnauthorized ||
|
|
httpError.StatusCode == http.StatusForbidden {
|
|
return ErrorCodeUnauthorized
|
|
}
|
|
return fmt.Sprintf("http_%d", httpError.StatusCode)
|
|
}
|
|
if errors.Is(err, context.DeadlineExceeded) {
|
|
return ErrorCodeTimeout
|
|
}
|
|
return ErrorCodeUnavailable
|
|
}
|