Skip to content

Commit

Permalink
Merge pull request #2 from mypricehealth/ra-fixNull
Browse files Browse the repository at this point in the history
Don't unmarshal empty
  • Loading branch information
robarchibald authored Aug 30, 2024
2 parents 045365b + b0bb4a8 commit b69065b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions GraphClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func NewGraphClient(tenantID, applicationID, clientSecret string) (*GraphClient,
// for azureADAuthEndpoint and serviceRootEndpoint are available via msgraph.azureADAuthEndpoint* and msgraph.ServiceRootEndpoint*
//
// For available endpoints from Microsoft, see documentation:
// * Authentication Endpoints: https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud#azure-ad-authentication-endpoints
// * Service Root Endpoints: https://docs.microsoft.com/en-us/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints
// - Authentication Endpoints: https://docs.microsoft.com/en-us/azure/active-directory/develop/authentication-national-cloud#azure-ad-authentication-endpoints
// - Service Root Endpoints: https://docs.microsoft.com/en-us/graph/deployments#microsoft-graph-and-graph-explorer-service-root-endpoints
//
// Returns an error if the token cannot be initialized. This func does not have
// to be used to create a new GraphClient.
Expand Down Expand Up @@ -154,7 +154,7 @@ func (g *GraphClient) makeDELETEAPICall(apiCall string, reqParams getRequestPara

// makeAPICall performs an API-Call to the msgraph API. This func uses sync.Mutex to synchronize all API-calls.
//
// Parameter httpMethod may be http.MethodGet, http.MethodPost or http.MethodPatch
// # Parameter httpMethod may be http.MethodGet, http.MethodPost or http.MethodPatch
//
// Parameter body may be nil to not provide any content - e.g. when using a http GET request.
func (g *GraphClient) makeAPICall(apiCall string, httpMethod string, reqParams getRequestParams, body io.Reader, v interface{}) error {
Expand Down Expand Up @@ -232,7 +232,10 @@ func (g *GraphClient) performRequest(req *http.Request, v interface{}) error {
if req.Method == http.MethodDelete || req.Method == http.MethodPatch {
return nil
}
return json.Unmarshal(body, &v) // return the error of the json unmarshal
if len(body) > 0 && v != nil {
return json.Unmarshal(body, &v) // return the error of the json unmarshal
}
return nil
}

// ListUsers returns a list of all users
Expand Down

0 comments on commit b69065b

Please sign in to comment.