Skip to content

Commit

Permalink
Use 'platform' errors in clinic client
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkazakov committed Oct 8, 2024
1 parent 5100baa commit 2b21ec7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
38 changes: 30 additions & 8 deletions clinics/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package clinics

import (
"context"
"fmt"
"net/http"

"github.com/tidepool-org/platform/errors"
Expand Down Expand Up @@ -85,7 +84,11 @@ func (d *defaultClient) GetClinician(ctx context.Context, clinicID, clinicianID
return nil, nil
}
if response.StatusCode() != http.StatusOK {
return nil, fmt.Errorf("unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.Preparedf(ErrorCodeClinicClientFailure,
"Unexpected status code from clinic service",
"unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.WithMeta(err, response.HTTPResponse)
return nil, err
}
return response.JSON200, nil
}
Expand All @@ -105,7 +108,11 @@ func (d *defaultClient) ListEHREnabledClinics(ctx context.Context) ([]clinic.Cli
return nil, err
}
if response.StatusCode() != http.StatusOK {
return nil, fmt.Errorf("unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.Preparedf(ErrorCodeClinicClientFailure,
"Unexpected status code from clinic service",
"unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.WithMeta(err, response.HTTPResponse)
return nil, err
}
if response.JSON200 == nil {
break
Expand All @@ -128,8 +135,11 @@ func (d *defaultClient) GetEHRSettings(ctx context.Context, clinicId string) (*c
return nil, err
}
if response.StatusCode() != http.StatusOK || response.StatusCode() != http.StatusOK {

return nil, fmt.Errorf("unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.Preparedf(ErrorCodeClinicClientFailure,
"Unexpected status code from clinic service",
"unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.WithMeta(err, response.HTTPResponse)
return nil, err
}
return response.JSON200, nil
}
Expand All @@ -151,7 +161,11 @@ func (d *defaultClient) SharePatientAccount(ctx context.Context, clinicID, patie
return d.getPatient(ctx, clinicID, patientID)
}
if response.StatusCode() != http.StatusOK {
return nil, fmt.Errorf("unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.Preparedf(ErrorCodeClinicClientFailure,
"Unexpected status code from clinic service",
"unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.WithMeta(err, response.HTTPResponse)
return nil, err
}
return response.JSON200, nil
}
Expand All @@ -162,7 +176,11 @@ func (d *defaultClient) SyncEHRData(ctx context.Context, clinicID string) error
return err
}
if response.StatusCode() != http.StatusAccepted {
return fmt.Errorf("unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.Preparedf(ErrorCodeClinicClientFailure,
"Unexpected status code from clinic service",
"unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.WithMeta(err, response.HTTPResponse)
return err
}
return nil
}
Expand All @@ -173,7 +191,11 @@ func (d *defaultClient) getPatient(ctx context.Context, clinicID, patientID stri
return nil, err
}
if response.StatusCode() != http.StatusOK {
return nil, fmt.Errorf("unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.Preparedf(ErrorCodeClinicClientFailure,
"Unexpected status code from clinic service",
"unexpected response status code %v from %v", response.StatusCode(), response.HTTPResponse.Request.URL)
err = errors.WithMeta(err, response.HTTPResponse)
return nil, err
}
return response.JSON200, nil
}
Expand Down
4 changes: 3 additions & 1 deletion ehr/sync/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"time"

"github.com/tidepool-org/platform/errors"

"github.com/tidepool-org/platform/pointer"
"github.com/tidepool-org/platform/task"
)
Expand Down Expand Up @@ -33,7 +35,7 @@ func NewTaskCreate(clinicId string, cadence time.Duration) *task.TaskCreate {
func GetClinicId(data map[string]interface{}) (string, error) {
clinicId, ok := data["clinicId"].(string)
if !ok {
return "", fmt.Errorf("unable to get clinicId from task data")
return "", errors.New("unable to get clinicId from task data")
}
return clinicId, nil
}
Expand Down

0 comments on commit 2b21ec7

Please sign in to comment.