planner icon indicating copy to clipboard operation
planner copied to clipboard

Improve exception handling in Flodesk::Client

Open mikej opened this issue 5 months ago • 0 comments

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

mikej avatar Aug 28 '25 15:08 mikej