Improve exception handling in Flodesk::Client
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 → Fixed on https://github.com/codebar/planner/pull/2402Flodesk::Client in the specs.