From 6b9fcc549a79a91922fd573ff39086c297a35a42 Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Fri, 9 Apr 2021 12:21:51 +0200 Subject: [PATCH] Wrap errors and handle empty responses better Signed-off-by: Andy Lo-A-Foe --- cdr/operations_stu3_service.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cdr/operations_stu3_service.go b/cdr/operations_stu3_service.go index c705df4c..08289172 100644 --- a/cdr/operations_stu3_service.go +++ b/cdr/operations_stu3_service.go @@ -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 @@ -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 @@ -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