Skip to content

Commit 418ed6d

Browse files
committed
Add requested path to exception message of NotFoundError
1 parent e45a454 commit 418ed6d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/openapi_first/failure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module OpenapiFirst
55
# This returned in ValidatedRequest#error and ValidatedResponse#error.
66
class Failure
77
TYPES = {
8-
not_found: [NotFoundError, 'Request path is not defined.'],
8+
not_found: [NotFoundError, 'Not found.'],
99
method_not_allowed: [RequestInvalidError, 'Request method is not defined.'],
1010
unsupported_media_type: [RequestInvalidError, 'Request content type is not defined.'],
1111
invalid_body: [RequestInvalidError, 'Request body invalid:'],

lib/openapi_first/router.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def add_response(response, request_method:, path:, status:, response_content_typ
5454
# Return all request objects that match the given path and request method
5555
def match(request_method, path, content_type: nil)
5656
path_item, params = find_path_item(path)
57-
return NOT_FOUND unless path_item
57+
unless path_item
58+
message = "Request path #{path} is not defined in API description."
59+
return NOT_FOUND.with(error: Failure.new(:not_found, message:))
60+
end
5861

5962
contents = path_item.dig(request_method, :requests)
6063
return NOT_FOUND.with(error: Failure.new(:method_not_allowed)) unless contents

0 commit comments

Comments
 (0)