diff --git a/utils/error.go b/utils/error.go new file mode 100644 index 00000000..e15a0948 --- /dev/null +++ b/utils/error.go @@ -0,0 +1,25 @@ +package utils + +import ( + "fmt" + "io" + "net/http" +) + +type HttpResponseError struct { + Code int + Message string +} + +func toHttpResponseError(response *http.Response) *HttpResponseError { + body, _ := io.ReadAll(response.Body) + response.Body.Close() + return &HttpResponseError{ + Code: response.StatusCode, + Message: string(body), + } +} + +func (m *HttpResponseError) Error() string { + return fmt.Sprintf("\nHTTP Response Code: %d\nError Message: %s", m.Code, m.Message) +} diff --git a/utils/qovery.go b/utils/qovery.go index 0057b99f..cdabdd42 100644 --- a/utils/qovery.go +++ b/utils/qovery.go @@ -1725,11 +1725,11 @@ func DeleteServices(client *qovery.APIClient, envId string, serviceIds []string, return DeleteServices(client, envId, serviceIds, serviceType) } -func DeployService(client *qovery.APIClient, envId string, serviceId string, serviceType ServiceType, request interface{}, watchFlag bool) (string, error) { - statuses, _, err := client.EnvironmentMainCallsAPI.GetEnvironmentStatuses(context.Background(), envId).Execute() +func DeployService(client *qovery.APIClient, envId string, serviceId string, serviceType ServiceType, request interface{}, watchFlag bool) (string, *HttpResponseError) { + statuses, resp, err := client.EnvironmentMainCallsAPI.GetEnvironmentStatuses(context.Background(), envId).Execute() if err != nil { - return "", err + return "", toHttpResponseError(resp) } if IsTerminalState(statuses.GetEnvironment().State) { @@ -1738,9 +1738,9 @@ func DeployService(client *qovery.APIClient, envId string, serviceId string, ser for _, application := range statuses.GetApplications() { if application.Id == serviceId && IsTerminalState(application.State) { req := request.(qovery.DeployRequest) - _, _, err := client.ApplicationActionsAPI.DeployApplication(context.Background(), serviceId).DeployRequest(req).Execute() + _, resp, err := client.ApplicationActionsAPI.DeployApplication(context.Background(), serviceId).DeployRequest(req).Execute() if err != nil { - return "", err + return "", toHttpResponseError(resp) } // get current deployment id @@ -1757,7 +1757,7 @@ func DeployService(client *qovery.APIClient, envId string, serviceId string, ser if database.Id == serviceId && IsTerminalState(database.State) { _, _, err := client.DatabaseActionsAPI.DeployDatabase(context.Background(), serviceId).Execute() if err != nil { - return "", err + return "", toHttpResponseError(resp) } if watchFlag { @@ -1773,7 +1773,7 @@ func DeployService(client *qovery.APIClient, envId string, serviceId string, ser req := request.(qovery.ContainerDeployRequest) _, _, err := client.ContainerActionsAPI.DeployContainer(context.Background(), serviceId).ContainerDeployRequest(req).Execute() if err != nil { - return "", err + return "", toHttpResponseError(resp) } if watchFlag { @@ -1789,7 +1789,7 @@ func DeployService(client *qovery.APIClient, envId string, serviceId string, ser req := request.(qovery.JobDeployRequest) _, _, err := client.JobActionsAPI.DeployJob(context.Background(), serviceId).JobDeployRequest(req).Execute() if err != nil { - return "", err + return "", toHttpResponseError(resp) } if watchFlag {