Skip to content

Commit

Permalink
Fix NilAssertionError when Docker engine returns codes like 304 Not M…
Browse files Browse the repository at this point in the history
…odified (#12)

When docker engine returns HTTP Not Modified, there's no body and so: `NilAssertionError HTTP::Client::Response#body_io cannot be nil`... check for nil and return a generic message if no response body.
  • Loading branch information
atlantis committed May 3, 2024
1 parent 22fdcb7 commit 59fb466
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/docr/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Docr
def call(method : String, url : String | URI, headers : HTTP::Headers | Nil = nil, body : IO | Slice(UInt8) | String | Nil = nil, &)
@client.exec(method, url, headers, body) do |response|
unless response.success?
body = response.body_io.gets_to_end
body = response.body_io?.try(&.gets_to_end) || "{\"message\": \"No response body\"}"
error = Docr::Types::ErrorResponse.from_json(body)

# Raise a custom DockerAPIError exception with the error message and status code.
Expand Down

0 comments on commit 59fb466

Please sign in to comment.