diff --git a/sdk/client/apps.go b/sdk/client/apps.go index f6fbe2a..cc2af93 100644 --- a/sdk/client/apps.go +++ b/sdk/client/apps.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "fmt" + "io" "net/http" sdkhttp "edp.buildth.ing/DevFW-CICD/edge-connect-client/sdk/internal/http" @@ -195,9 +196,9 @@ func (c *Client) getTransport() *sdkhttp.Transport { return sdkhttp.NewTransport( sdkhttp.RetryOptions{ MaxRetries: c.RetryOpts.MaxRetries, - InitialDelay: c.RetryOpts.InitialDelay, - MaxDelay: c.RetryOpts.MaxDelay, - Multiplier: c.RetryOpts.Multiplier, + InitialDelay: c.RetryOpts.InitialDelay, + MaxDelay: c.RetryOpts.MaxDelay, + Multiplier: c.RetryOpts.Multiplier, RetryableHTTPStatusCodes: c.RetryOpts.RetryableHTTPStatusCodes, }, c.AuthProvider, @@ -207,8 +208,22 @@ func (c *Client) getTransport() *sdkhttp.Transport { // handleErrorResponse creates an appropriate error from HTTP error response func (c *Client) handleErrorResponse(resp *http.Response, operation string) error { + + messages := []string{ + fmt.Sprintf("%s failed with status %d", operation, resp.StatusCode), + } + + bodyBytes := []byte{} + + if resp.Body != nil { + defer resp.Body.Close() + bodyBytes, _ = io.ReadAll(resp.Body) + messages = append(messages, string(bodyBytes)) + } + return &APIError{ StatusCode: resp.StatusCode, - Messages: []string{fmt.Sprintf("%s failed with status %d", operation, resp.StatusCode)}, + Messages: messages, + Body: bodyBytes, } -} \ No newline at end of file +} diff --git a/sdk/client/types.go b/sdk/client/types.go index 16b14e4..1a9e44c 100644 --- a/sdk/client/types.go +++ b/sdk/client/types.go @@ -3,7 +3,11 @@ package client -import "time" +import ( + "encoding/json" + "fmt" + "time" +) // Message interface for types that can provide error messages type Message interface { @@ -79,16 +83,16 @@ type AppInstance struct { // Cloudlet represents edge infrastructure type Cloudlet struct { - msg `json:",inline"` - Key CloudletKey `json:"key"` - Location Location `json:"location"` - IpSupport string `json:"ip_support,omitempty"` - NumDynamicIps int32 `json:"num_dynamic_ips,omitempty"` - State string `json:"state,omitempty"` - Flavor Flavor `json:"flavor,omitempty"` - PhysicalName string `json:"physical_name,omitempty"` - Region string `json:"region,omitempty"` - NotifySrvAddr string `json:"notify_srv_addr,omitempty"` + msg `json:",inline"` + Key CloudletKey `json:"key"` + Location Location `json:"location"` + IpSupport string `json:"ip_support,omitempty"` + NumDynamicIps int32 `json:"num_dynamic_ips,omitempty"` + State string `json:"state,omitempty"` + Flavor Flavor `json:"flavor,omitempty"` + PhysicalName string `json:"physical_name,omitempty"` + Region string `json:"region,omitempty"` + NotifySrvAddr string `json:"notify_srv_addr,omitempty"` } // Location represents geographical coordinates @@ -181,10 +185,11 @@ type APIError struct { } func (e *APIError) Error() string { - if len(e.Messages) > 0 { - return e.Messages[0] + jsonErr, err := json.Marshal(e) + if err != nil { + return fmt.Sprintf("API error: %v", err) } - return "API error" + return fmt.Sprintf("API error: %s", jsonErr) } // Filter types for querying @@ -209,7 +214,7 @@ type CloudletFilter struct { // CloudletManifest represents cloudlet deployment manifest type CloudletManifest struct { - Manifest string `json:"manifest"` + Manifest string `json:"manifest"` LastModified time.Time `json:"last_modified,omitempty"` } @@ -218,4 +223,4 @@ type CloudletResourceUsage struct { CloudletKey CloudletKey `json:"cloudlet_key"` Region string `json:"region"` Usage map[string]interface{} `json:"usage"` -} \ No newline at end of file +} diff --git a/sdk/examples/deploy_app.go b/sdk/examples/deploy_app.go index ae6e7b6..861f6d3 100644 --- a/sdk/examples/deploy_app.go +++ b/sdk/examples/deploy_app.go @@ -55,7 +55,7 @@ func main() { Name: "my-edge-app", Version: "1.0.0", }, - Deployment: "kubernetes", + Deployment: "docker", ImageType: "ImageTypeDocker", ImagePath: "nginx:latest", DefaultFlavor: client.Flavor{Name: "EU.small"}, @@ -80,7 +80,7 @@ func demonstrateAppLifecycle(ctx context.Context, edgeClient *client.Client, inp // Step 1: Create the application fmt.Println("\n1. Creating application...") if err := edgeClient.CreateApp(ctx, input); err != nil { - return fmt.Errorf("failed to create app: %w", err) + return fmt.Errorf("failed to create app: %+v", err) } fmt.Printf("✅ App created: %s/%s v%s\n", appKey.Organization, appKey.Name, appKey.Version)