Skip to content

Commit 85c08c9

Browse files
Improve content type mismatch error message
1 parent 3af8504 commit 85c08c9

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/openapi_first/router/find_response.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ def self.call(responses, status, content_type, request_method:, path:)
1717
end
1818
response = FindContent.call(contents, content_type)
1919
if response.nil?
20-
message = "#{content_error(content_type, request_method:,
21-
path:)} Content-Type should be #{contents.keys.join(' or ')}."
22-
return Match.new(error: Failure.new(:response_not_found, message:), response: nil)
20+
message =
21+
"Content-Type should be #{contents.keys.join(" or ")}, " \
22+
"but was #{content_type&.empty? ? "empty" : content_type} for " \
23+
"#{request_method} #{path}"
24+
return(
25+
Match.new(
26+
error: Failure.new(:response_not_found, message:),
27+
response: nil
28+
)
29+
)
2330
end
2431

2532
Match.new(response:, error: nil)
2633
end
2734

28-
def self.content_error(content_type, request_method:, path:)
29-
return 'Response Content-Type must not be empty.' if content_type.nil? || content_type.empty?
30-
31-
"Response Content-Type #{content_type} is not defined for #{request_method} #{path}."
32-
end
33-
3435
def self.find_status(responses, status)
3536
# According to OAS status has to be a string,
3637
# but there are a few API descriptions out there that use integers because of YAML.

0 commit comments

Comments
 (0)