Skip to content

Commit

Permalink
fix: create facility
Browse files Browse the repository at this point in the history
- return an error describing the reason of failure

Signed-off-by: Kathurima Kimathi <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Oct 18, 2023
1 parent 2d376d1 commit fd3488e
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions healthcrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func (h *HealthCRMLib) CreateFacility(ctx context.Context, facility *Facility) (
return nil, err
}

if response.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("unable to create facility in the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusCreated {
return nil, fmt.Errorf("unable to create facility in the registry with error %v", string(respBytes))
}

var facilityResponse *FacilityOutput

err = json.Unmarshal(respBytes, &facilityResponse)
Expand All @@ -67,15 +67,15 @@ func (h *HealthCRMLib) GetFacilities(ctx context.Context) (*FacilityPage, error)
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch facility(ies) in the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch facility(ies) in the registry with error: %v", string(respBytes))
}

var facilityPage *FacilityPage

err = json.Unmarshal(respBytes, &facilityPage)
Expand All @@ -94,15 +94,15 @@ func (h *HealthCRMLib) GetFacilityByID(ctx context.Context, id string) (*Facilit
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch facility from the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to fetch facility from the registry with error: %v", string(respBytes))
}

var facilityOutput *FacilityOutput

err = json.Unmarshal(respBytes, &facilityOutput)
Expand All @@ -121,15 +121,15 @@ func (h *HealthCRMLib) UpdateFacility(ctx context.Context, id string, updatePayl
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to update facility in the registry with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to update facility in the registry with error: %v", string(respBytes))
}

var facilityOutput *FacilityOutput

err = json.Unmarshal(respBytes, &facilityOutput)
Expand Down Expand Up @@ -163,15 +163,15 @@ func (h *HealthCRMLib) GetFacilityServices(ctx context.Context, facilityID strin
resp = response
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to get facility services with status code: %v", resp.StatusCode)
}

respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to get facility services with error: %v", string(respBytes))
}

var facilityServicePage *FacilityServicePage

err = json.Unmarshal(respBytes, &facilityServicePage)
Expand All @@ -193,15 +193,15 @@ func (h *HealthCRMLib) GetFacilitiesOfferingAService(ctx context.Context, servic
return nil, err
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to get facilities offering service with status code: %v", response.StatusCode)
}

respBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("could not read response: %w", err)
}

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to get facilities offering service with error: %v", string(respBytes))
}

var output *FacilityPage

err = json.Unmarshal(respBytes, &output)
Expand Down

0 comments on commit fd3488e

Please sign in to comment.