From fdc2b3ab1bc88b87f7b4903492dbb8dfe7d10f12 Mon Sep 17 00:00:00 2001 From: Preston Baxter Date: Tue, 21 Nov 2023 19:58:38 -0600 Subject: [PATCH] B: add response message to error logging --- service/vendors/pco/webhooks.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/service/vendors/pco/webhooks.go b/service/vendors/pco/webhooks.go index 2730111..2e55d9a 100644 --- a/service/vendors/pco/webhooks.go +++ b/service/vendors/pco/webhooks.go @@ -3,6 +3,7 @@ package pco import ( "bytes" "fmt" + "io" "net/http" "git.preston-baxter.com/Preston_PLB/capstone/webhook-service/vendors/pco/webhooks" @@ -23,8 +24,13 @@ func (api *PcoApiClient) GetSubscriptions() ([]webhooks.Subscription, error) { return nil, err } + if resp.StatusCode > 299 || resp.StatusCode < 200 { - return nil, fmt.Errorf("Failed to retrieve subscriptions with status code: %d", resp.StatusCode) + if raw, err := io.ReadAll(resp.Body); err != nil { + return nil, fmt.Errorf("Failed to retrieve subscriptions with status code: %d. Error %s", resp.StatusCode, string(raw)) + } else { + return nil, fmt.Errorf("Failed to retrieve subscriptions with status code: %d", resp.StatusCode) + } } subscriptions, err := jsonapi.UnmarshalManyPayload[webhooks.Subscription](resp.Body) @@ -56,7 +62,11 @@ func (api *PcoApiClient) CreateSubscriptions(subscriptions []webhooks.Subscripti } if resp.StatusCode > 299 || resp.StatusCode < 200 { - return nil, fmt.Errorf("Failed to retrieve plan with status code: %d", resp.StatusCode) + if raw, err := io.ReadAll(resp.Body); err != nil { + return nil, fmt.Errorf("Failed to retrieve subscriptions with status code: %d. Error %s", resp.StatusCode, string(raw)) + } else { + return nil, fmt.Errorf("Failed to retrieve subscriptions with status code: %d", resp.StatusCode) + } } new_subscriptions, err := jsonapi.UnmarshalManyPayload[webhooks.Subscription](resp.Body) @@ -88,7 +98,11 @@ func (api *PcoApiClient) CreateSubscription(subscription *webhooks.Subscription) } if resp.StatusCode > 299 || resp.StatusCode < 200 { - return fmt.Errorf("Failed to retrieve plan with status code: %d", resp.StatusCode) + if raw, err := io.ReadAll(resp.Body); err != nil { + return fmt.Errorf("Failed to retrieve subscriptions with status code: %d. Error %s", resp.StatusCode, string(raw)) + } else { + return fmt.Errorf("Failed to retrieve subscriptions with status code: %d", resp.StatusCode) + } } err = jsonapi.UnmarshalPayload(resp.Body, subscription)