Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unmarshal empty #2

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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