Skip to content

Commit

Permalink
[crystal-lang] Resolve type check compile error in ApiError (#18759)
Browse files Browse the repository at this point in the history
* Even with .nil? typecheck, compiler still fails due to .empty? call on nillable type. This appears a poor implementation issue by crystal-lang, but this explicit try avoids the issue for now.

* Made call more succinct.
  • Loading branch information
usiegj00 committed May 26, 2024
1 parent e6fcbcb commit 77365c3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module {{moduleName}}
msg = ""
msg = msg + "\nHTTP status code: #{code}" if @code
msg = msg + "\nResponse headers: #{response_headers}" if @response_headers
if @message.nil? || @message.empty?
if @message.try &.empty?
msg = msg + "\nError message: the server returns an error but the HTTP response body is empty."
else
msg = msg + "\nResponse body: #{@message}"
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/crystal/src/petstore/api_error.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Petstore
msg = ""
msg = msg + "\nHTTP status code: #{code}" if @code
msg = msg + "\nResponse headers: #{response_headers}" if @response_headers
if @message.nil? || @message.empty?
if @message.try &.empty?
msg = msg + "\nError message: the server returns an error but the HTTP response body is empty."
else
msg = msg + "\nResponse body: #{@message}"
Expand Down

0 comments on commit 77365c3

Please sign in to comment.