diff --git a/clinics/service.go b/clinics/service.go index 509fe51ee..97f538ccd 100644 --- a/clinics/service.go +++ b/clinics/service.go @@ -2,7 +2,6 @@ package clinics import ( "context" - "fmt" "net/http" "github.com/tidepool-org/platform/errors" @@ -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 } @@ -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 @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/ehr/sync/task.go b/ehr/sync/task.go index 426ddee26..803d4e3d4 100644 --- a/ehr/sync/task.go +++ b/ehr/sync/task.go @@ -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" ) @@ -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 }