Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log on unsuccessful responses #45

Merged
merged 17 commits into from
Dec 21, 2024

Conversation

al-yanna
Copy link
Contributor

@al-yanna al-yanna commented Dec 4, 2024

Context

We want to add warning logs on client-level error responses.

Changes

  • Log a warning when response code is >= 400 && < 500.
    • Extract errors (path & message) from the response body to include in the log message

Testing

Added unit tests
image

def extract_error_details(response)
parsed_body = JSON.parse(response.body)
return unless parsed_body.is_a?(Hash) && parsed_body["errors"].is_a?(Array)
parsed_body["errors"].map { |error| "path: #{error["path"]}, message: #{error["message"]}" }.join(", ")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"path" is the location of the error within the JSON structure of the request.

for example, if there is an error in the metadata: client property, it will be

"path": "/operations/0/metadata/client"

Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks great! Just wondering what the "error.message" looks like in the body? Just wondering if that is enough info to debug.

Knowing the field and reason would be huge though.

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 would look something like this, depending on the error:
image

@al-yanna al-yanna marked this pull request as ready for review December 4, 2024 22:09
@al-yanna al-yanna marked this pull request as draft December 5, 2024 02:21
Copy link
Collaborator

@aryascripts aryascripts left a comment

Choose a reason for hiding this comment

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

Looks good! Just a small nit about response.code

def extract_error_details(response)
parsed_body = JSON.parse(response.body)
return unless parsed_body.is_a?(Hash) && parsed_body["errors"].is_a?(Array)
parsed_body["errors"].map { |error| "path: #{error["path"]}, message: #{error["message"]}" }.join(", ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks great! Just wondering what the "error.message" looks like in the body? Just wondering if that is enough info to debug.

Knowing the field and reason would be huge though.

lib/graphql-hive/client.rb Outdated Show resolved Hide resolved
Co-authored-by: Arya Bhimani <[email protected]>
@al-yanna al-yanna marked this pull request as ready for review December 5, 2024 16:34
@al-yanna al-yanna marked this pull request as draft December 5, 2024 17:43
@al-yanna
Copy link
Contributor Author

al-yanna commented Dec 5, 2024

Converted to draft, #46 first to fix bug in version 0.5.2

lib/graphql-hive/client.rb Outdated Show resolved Hide resolved
@al-yanna al-yanna marked this pull request as ready for review December 17, 2024 21:59
Copy link
Collaborator

@cassidycodes cassidycodes left a comment

Choose a reason for hiding this comment

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

Thank you for doing this. Can you please add tests for the logging you've added.

lib/graphql-hive/client.rb Outdated Show resolved Hide resolved
lib/graphql-hive/client.rb Outdated Show resolved Hide resolved
@al-yanna
Copy link
Contributor Author

@rperryng this PR is ready to be merged! 🙏

@rperryng rperryng merged commit 6313562 into rperryng:master Dec 21, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants