Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit 29ef40e

Browse files
oleksandriuzikovsfroehler
authored andcommitted
Parse response only when it's not empty
Previously, _Shipcloud::Shipment.delete(ID)_ caused TypeError converting nil to String
1 parent af76b21 commit 29ef40e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
### Changed
1313

1414
### Fixed
15+
- Parse response only when it is not empty
1516

1617
## [0.7.0] - 2016-01-21
1718
### Added

lib/shipcloud/request/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def perform
1212
connection.setup_https
1313
response = connection.request
1414
validate_response(response)
15-
JSON.parse(response.body)
15+
JSON.parse(response.body) unless response.body.nil?
1616
rescue JSON::ParserError
1717
raise ShipcloudError.new(response)
1818
end

spec/shipcloud/shipment_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@
9898
and_return(true)
9999
Shipcloud::Shipment.delete("123")
100100
end
101+
102+
it "doesn't raise an error" do
103+
stub_request(:delete, "https://your-api-key:@api.shipcloud.io/v1/shipments/123").
104+
to_return(status: 204, body: "")
105+
expect { Shipcloud::Shipment.delete("123", api_key: "your-api-key") }.
106+
to_not raise_error
107+
end
101108
end
102109

103110
describe ".all" do

0 commit comments

Comments
 (0)