[crystal-lang] Resolve type check compile error in ApiError (#18759)

* 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.
This commit is contained in:
Jonathan Siegel 2024-05-26 12:44:07 +09:00 committed by GitHub
parent e6fcbcbde0
commit 77365c34fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -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}"

View File

@ -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}"