Microsoft Graph SDK - Patch operation result

juni dev 361 Reputation points
2022-11-06T23:10:53.383+00:00

Hi,

I need to update users via Graph SDK. It is working fine but I would like to detect when/if errors occur

I'm doing something similar to the SDK documentation samples but the operation result (althouh it succeeds) is always null
var myResult = await graphClient.Users[userId].Request().UpdateAsync(userUpdate);

Since myResult is always null, how can I detect if the update failed? Has to be via try/catch?

Sample doc
https://learn.microsoft.com/en-us/graph/sdks/create-requests?tabs=CS#updating-an-existing-entity-with-patch

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 46,371 Reputation points
    2022-11-07T09:32:06.417+00:00

    Hi @juni dev

    Yes, you can catch exceptions via try/catch.

    257760-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,161 Reputation points Microsoft Employee
    2022-11-07T08:31:24.457+00:00

    Yes, you want to handle the error, when your results are null/empty, you have to use try /catch for error handling

    if you want to know, how to use try /catch, you can see similar questions, where it explains in detail - https://stackoverflow.com/questions/62438792/microsoft-graph-error-responses-how-to-extract-http-status-code-and-inner-erro

    hope this helps
    Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.