Skip to content
Advertisement

MS Graph | PHP | GET Photo – Laravel 404 exception

I’m building a website with Azure authentication using MS Graph. As you can see below I want to login and get my own data as well as my managers which is working fine, however the issue begins when I want to select the photo.

JavaScript

When a user does not have a profile photo set it will return a 404 Not Found which is ok, but I don’t want my script to stop if there is no photo. What I want is something like this:

JavaScript

If there is no photo I want to set $avatar to null instead of getting the following error: Laravel error description

Thanks in advance!

FULL FUNCTION

JavaScript

Advertisement

Answer

Try to catch the exact exception the error is client exception of 404 status code try to catch it directly and catch its response. Also I have never heard of function $e->getResponseBody() it should be $e->getResponse() as given in guzzle docs. You can take more reference from this answer

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement