Skip to content

Commit

Permalink
Wrap errors and handle empty responses better
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Lo-A-Foe <[email protected]>
  • Loading branch information
loafoe committed Apr 9, 2021
1 parent ced629e commit 6b9fcc5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cdr/operations_stu3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (o *OperationsSTU3Service) Patch(resourceID string, jsonPatch []byte, optio
}
unmarshalled, err := o.um.Unmarshal(patchResponse.Bytes())
if err != nil {
return nil, resp, err
return nil, resp, fmt.Errorf("FHIR unmarshal: %w", err)
}
contained := unmarshalled.(*stu3pb.ContainedResource)
return contained, resp, nil
Expand Down Expand Up @@ -67,7 +67,7 @@ func (o *OperationsSTU3Service) Get(resourceID string, options ...OptionFunc) (*
}
unmarshalled, err := o.um.Unmarshal(operationResponse.Bytes())
if err != nil {
return nil, resp, err
return nil, resp, fmt.Errorf("FHIR unmarshal: %w", err)
}
contained := unmarshalled.(*stu3pb.ContainedResource)
return contained, resp, nil
Expand Down Expand Up @@ -105,9 +105,12 @@ func (o *OperationsSTU3Service) postOrPut(method, resourceID string, jsonBody []
}
return nil, resp, err
}
if operationResponse.Len() == 0 { // Empty body
return &stu3pb.ContainedResource{}, resp, nil
}
unmarshalled, err := o.um.Unmarshal(operationResponse.Bytes())
if err != nil {
return nil, resp, err
return nil, resp, fmt.Errorf("FHIR unmarshal: %w", err)
}
contained := unmarshalled.(*stu3pb.ContainedResource)
return contained, resp, nil
Expand Down

0 comments on commit 6b9fcc5

Please sign in to comment.