@@ -8,6 +8,7 @@ module Rails
8
8
module Support
9
9
class RailsDocumentClient
10
10
RAILS_DOC_HOST = "https://api.rubyonrails.org"
11
+
11
12
SUPPORTED_RAILS_DOC_NAMESPACES = T . let (
12
13
Regexp . union (
13
14
/ActionDispatch/ ,
@@ -31,9 +32,8 @@ class RailsDocumentClient
31
32
32
33
class << self
33
34
extend T ::Sig
34
- sig do
35
- params ( name : String ) . returns ( T ::Array [ String ] )
36
- end
35
+
36
+ sig { params ( name : String ) . returns ( T ::Array [ String ] ) }
37
37
def generate_rails_document_urls ( name )
38
38
docs = search_index &.fetch ( name , nil )
39
39
@@ -70,18 +70,20 @@ def generate_rails_document_urls(name)
70
70
71
71
response = Net ::HTTP . get_response ( URI ( "#{ RAILS_DOC_HOST } /v#{ RAILTIES_VERSION } /js/search_index.js" ) )
72
72
73
- if response . code == "302"
73
+ body = case response
74
+ when Net ::HTTPSuccess
75
+ response . body
76
+ when Net ::HTTPRedirection
74
77
# If the version's doc is not found, e.g. Rails main, it'll be redirected
75
78
# In this case, we just fetch the latest doc
76
79
response = Net ::HTTP . get_response ( URI ( "#{ RAILS_DOC_HOST } /js/search_index.js" ) )
77
- end
78
-
79
- if response . code == "200"
80
- process_search_index ( response . body )
80
+ response . body if response . is_a? ( Net ::HTTPSuccess )
81
81
else
82
82
warn ( "Response failed: #{ response . inspect } " )
83
83
nil
84
84
end
85
+
86
+ process_search_index ( body ) if body
85
87
rescue StandardError => e
86
88
warn ( "Exception occurred when fetching Rails document index: #{ e . inspect } " )
87
89
end
0 commit comments