Skip to content

Conversation

@Ndiritu
Copy link
Contributor

@Ndiritu Ndiritu commented Jun 28, 2021

Changes that differ from initial design doc

  • HttpClientFactory will only initialise a Guzzle client, not support other HTTP clients
  • Other clients will be usable through the Graph client, however the telemetry and auth headers will be added to the GraphRequest object
  • removed setting apiVersion() in the HttpClientFactory since setting the base URL to https://[national cloud]/[apiVersion] would mean customers need to pass and endpoint without a leading / for the correct URL to be resolved by Guzzle. Our docs provide endpoints with the leading /. Api version will be appended to nationalCloud in the GraphRequest before sending it
  • accepting a Guzzle client config array in the HttpClientFactory & Graph class as opposed to a Guzzle client object.
    Guzzle plans to deprecate functionality (getConfig()) that would allow us to get the config array that was used to initialise a client in Guzzle 8. Impact is, if the SDK accepts a Guzzle client object, we would be unable to set default configs while preserving any custom configs the customer may have used.

FYI

Thought it would be easier to have this PR first to show the HttpClientFactory and its integration into the Graph client.

To reduce the number of changes per PR, I'll create other branches off philip/feat/http-client-factory with changes to other classes that are affected by this feature - GraphRequest, various failing tests etc.

Once this PR is approved, the other PRs will be merged into the current branch before merging to main.

Note: Tests currently failing. Will be fixed in subsequent "child" branches of the current branch then merged.

Closes https://github.com/microsoftgraph/msgraph-sdk-php/issues/438
Closes microsoftgraph/msgraph-sdk-php#531

@Ndiritu
Copy link
Contributor Author

Ndiritu commented Jun 29, 2021

Sorry about lots of whitespace changes. Trying to get that sorted.

* @link https://developer.microsoft.com/graph
*/
class ClientInitialisationException extends GraphException
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It extends all functionality of the GraphException with nothing custom to add.

Thanks for pointing out a bug though, I need to change GraphException's __toString() to print the child class name where needed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of GraphException class?

For the JS SDK, @MIchaelMainer had suggested creating a GraphCientError class which handles the errors such as ClientInitialisationException and a GraphError class which handles errors from the API.

I would suggest using something similar because:

  • There is a sync in the SDKs
  • Avoid creating an empty class if you are not extending or adding more functionalities.
  • A generic GraphClientError class with clear messages reduces the need to create multiple class depending on the feature. For example, ClientInitialization, an error class for PageIteration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this! We still need to better define our error classification. At a high-level, we have two primary exceptions: ServiceException that represents errors returned in an API response and ClientException for issues raised in the client. Both of these can extend GraphException.

I just created a quick PR to help us be more consistent.

microsoftgraph/msgraph-sdk-design#47

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ClientInitialisationException to GraphClientException

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ndiritu Graph Exception that is the parent class is it the service exception class?
What is the class which captures the Graph API error response?

If GraphException is the service error response class then I recommend you to keep them separate as mentioned by @MIchaelMainer in the PR microsoftgraph/msgraph-sdk-design#47

I suppose you can address this in a separate PR focusing on the error classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikithauc Yes, i'll need to make these changes in a separate PR.

@Ndiritu
Copy link
Contributor Author

Ndiritu commented Jul 3, 2021

Thanks for the thought-provoking feedback @nikithauc! I've addressed all issues/comments raised.

@nikithauc
Copy link

Thanks for the thought-provoking feedback @nikithauc! I've addressed all issues/comments raised.

Thanks for addressing the issues!! Appreciate your efforts in improving the core library.

@Ndiritu Ndiritu changed the base branch from main to dev August 18, 2021 21:55
@Ndiritu Ndiritu merged commit 14df451 into dev Aug 18, 2021
@Ndiritu Ndiritu deleted the philip/feat/http-client-factory branch October 28, 2021 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GraphClientFactory for PHP Support multiple HTTP clients

3 participants