Files
zeekay 6f93520c46 refactor: rebrand Infisical Go SDK -> Hanzo KMS Go SDK
- Module path: github.com/infisical/go-sdk -> github.com/hanzokms/go-sdk
- Package name: infisical -> kms
- Types: InfisicalClient -> Client, NewInfisicalClient -> NewClient
- Default URL: app.infisical.com -> kms.hanzo.ai
- Env vars: INFISICAL_ prefix -> KMS_ prefix
- User agent: infisical-go-sdk -> hanzo-kms-go-sdk
- Copyright: Hanzo AI Inc.
- go build ./... passes clean
2026-02-24 01:58:24 -08:00

60 lines
1.3 KiB
Go

package errors
import (
"fmt"
"github.com/go-resty/resty/v2"
"github.com/hanzokms/go-sdk/packages/util"
)
// APIError represents an error response from the API
type APIError struct {
Operation string `json:"operation"`
Method string `json:"method"`
URL string `json:"url"`
StatusCode int `json:"statusCode"`
ErrorMessage string `json:"message,omitempty"`
ReqId string `json:"reqId,omitempty"`
}
func (e *APIError) Error() string {
msg := fmt.Sprintf(
"APIError: %s unsuccessful response [%v %v] [status-code=%v] [reqId=%v]",
e.Operation,
e.Method,
e.URL,
e.StatusCode,
e.ReqId,
)
if e.ErrorMessage != "" {
return fmt.Sprintf("%s [message=\"%s\"]", msg, e.ErrorMessage)
}
return msg
}
func NewAPIError(operation string, res *resty.Response) error {
return &APIError{
Operation: operation,
Method: res.Request.Method,
URL: res.Request.URL,
StatusCode: res.StatusCode(),
}
}
func NewAPIErrorWithResponse(operation string, res *resty.Response) error {
errorMessage := util.TryParseErrorBody(res)
reqId := util.TryExtractReqId(res)
return &APIError{
Operation: operation,
Method: res.Request.Method,
URL: res.Request.URL,
StatusCode: res.StatusCode(),
ErrorMessage: errorMessage,
ReqId: reqId,
}
}