Improve exception handling in Flodesk::Client
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 104
- Forks
- 205
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 63
Description
Currently we've got the following code in Client#request:
Make code nil-safe
This can result in a NoMethodError: undefined method '[]' for nil if there is an issue connecting to Flodesk and the response doesn't actually contain a message_body.
This could happen in production, but also can be a source of flaky tests as happened recently.
Proposing to make this nil-safe by using e.response_body&.['message']
Raise rather than return the exception
Currently this code is actually returning the FlodeskError rather than raising it.
Proposing to raise the exception instead, but note there's one place where we currently check the return type from the method that will need updating to reflect this change:
Mock out the client in tests
As a separate task we can take a look at mocking → Fixed on https://github.com/codebar/planner/pull/2402Flodesk::Client in the specs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/flodesk.rb at Client#request and inspect the return-type check around lines 70–74. Verify the connection-error path when response_body is absent, update the caller behavior, and run the existing Flodesk-related specs to confirm errors are raised and the nil case no longer causes a NoMethodError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100