microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Photos API throws when there are no photos

Open
#2,673 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type:bug
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

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["someuserWithoutAPhoto@domain.com"].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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the no-photo request through Users["someuserWithoutAPhoto@domain.com"].Photos.GetAsync(), then inspect the generated Photos.Item.Value.ContentRequestBuilder.GetAsync path and the HttpClientRequestAdapter error handling shown in the stack trace. Done means the no-photo case has an agreed, tested SDK behavior rather than requiring an unhandled exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.