msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Photos API throws when there are no photos

Open andre-ss6 opened this issue 1 year ago • 0 comments

Describe the bug

I'm trying to fetch user profile photos. However, calling the API for users that haven't set their profile photo returns 404 with an exception message. The issue is that the Graph SDK currently throws in that case and there is no way to previously check if the user has or not a photo, so the only alternative left is to always try/catch.

Expected behavior

Either return null, some kind of empty type or provide an API for querying the photo count

How to reproduce

Invoke _graphClient.Users["[email protected]"].Photos.GetAsync(). Result: Exception: Microsoft.Graph.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Fast.Profile.Core.Exception.ImageNotFoundException' was thrown.

SDK Version

5.58.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ``` Exception: Microsoft.Graph.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Fast.Profile.Core.Exception.ImageNotFoundException' was thrown. at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponseAsync(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendPrimitiveAsync[ModelType](RequestInformation requestInfo, Dictionary`2 errorMapping, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendPrimitiveAsync[ModelType](RequestInformation requestInfo, Dictionary`2 errorMapping, CancellationToken cancellationToken) at Microsoft.Graph.Users.Item.Photos.Item.Value.ContentRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken) at [redacted].MessageOnPRActivity.Run(HttpRequest req) in [redacted]\MessageOnPRActivity.cs:line 184 at [redacted].DirectFunctionExecutor.ExecuteAsync(FunctionContext context) in [redacted]\obj\Debug\net8.0\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:line 38 at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13 at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48 at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 89 Stack: at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponseAsync(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendPrimitiveAsync[ModelType](RequestInformation requestInfo, Dictionary`2 errorMapping, CancellationToken cancellationToken) at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendPrimitiveAsync[ModelType](RequestInformation requestInfo, Dictionary`2 errorMapping, CancellationToken cancellationToken) at Microsoft.Graph.Users.Item.Photos.Item.Value.ContentRequestBuilder.GetAsync(Action`1 requestConfiguration, CancellationToken cancellationToken) at [redacted].MessageOnPRActivity.Run(HttpRequest req) in [redacted]\MessageOnPRActivity.cs:line 184 at [redacted].DirectFunctionExecutor.ExecuteAsync(FunctionContext context) in [redacted]\obj\Debug\net8.0\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:line 38 at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13 at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 48 at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 89

Configuration

  • OS: Windows x64
  • Not specific to this configuration AFAIK

Other information

No response

andre-ss6 avatar Sep 19 '24 23:09 andre-ss6