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: adds error handling for OpenApi errors #166

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

ctran88
Copy link
Contributor

@ctran88 ctran88 commented Jan 10, 2025

What's New?

  • the errors that come back from our API servers are not Faraday errors, but OpenapiClient instead
  • also fixes another error where the param guard wasn't correctly checking an empty '' string
    • this fix will be added as a separate line item in the squash commit message

Screenshots (if appropriate):

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have manually tested my code thoroughly
  • I have added/updated inline documentation for public facing interfaces if relevant
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing integration and unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional context

@ctran88 ctran88 force-pushed the PSG-5718-fix-error-handling branch from 0fbea15 to 982974a Compare January 10, 2025 20:55
@@ -13,3 +13,5 @@ Layout/LineLength:
Metrics/MethodLength:
Max: 50

Metrics/AbcSize:
Max: 20
Copy link
Contributor Author

@ctran88 ctran88 Jan 10, 2025

Choose a reason for hiding this comment

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

i was getting linter errors that code like this was too complicated with a score of 18.79/17

def revoke_device(user_id:, device_id:)
raise ArgumentError, 'user_id is required.' unless user_id && !user_id.empty?
raise ArgumentError, 'device_id is required.' unless device_id && !device_id.empty?
begin
@user_device_client.delete_user_devices(@app_id, user_id, device_id, @req_opts)
rescue OpenapiClient::ApiError => e
raise PassageError.new(
status_code: e.code,
body: try_parse_json_string(e.response_body)
)
rescue Faraday::Error => e
raise PassageError.new(
status_code: e.response[:status],
body: e.response[:body]
)
end
end

but i figured that's not too bad, so adjusting this limit instead

@ctran88 ctran88 marked this pull request as ready for review January 10, 2025 20:57
@ctran88 ctran88 force-pushed the PSG-5718-fix-error-handling branch from e712cec to bcbdce2 Compare January 10, 2025 21:55
@@ -208,6 +211,11 @@ def revoke_refresh_tokens(user_id:)

private

def blank_str(str)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Ruby methods that return a boolean typically end with a question mark.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ctran88 ctran88 closed this Jan 13, 2025
@ctran88 ctran88 reopened this Jan 13, 2025
@ctran88 ctran88 requested a review from bertrmz January 13, 2025 17:20
@ctran88 ctran88 merged commit 827bc5c into main Jan 13, 2025
10 checks passed
@ctran88 ctran88 deleted the PSG-5718-fix-error-handling branch January 13, 2025 17:26
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.

2 participants