codebar / codebar/planner

Improve exception handling in Flodesk::Client

Open
#2,321 0 comments 1 reaction 0 assignees View on GitHub

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:

https://github.com/codebar/planner/blob/45fd9d14f91bbbc80c13412983b51d75ff285c57/lib/flodesk.rb#L128-L133

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:

https://github.com/codebar/planner/blob/45fd9d14f91bbbc80c13412983b51d75ff285c57/lib/flodesk.rb#L70-L74

Mock out the client in tests

As a separate task we can take a look at mocking Flodesk::Client in the specs. → Fixed on https://github.com/codebar/planner/pull/2402

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.