@@ -122,12 +122,6 @@ type fetchResult struct {
122
122
err error
123
123
}
124
124
125
- var statusToResponseText = map [int ]string {
126
- http .StatusOK : "" ,
127
- http .StatusRequestTimeout : "We're still working on your request - come back in a few minutes!" ,
128
- http .StatusInternalServerError : "Something went wrong. We'll keep working on it - try again in a few minutes!" ,
129
- }
130
-
131
125
func (s * Server ) fetchAndPoll (ctx context.Context , ds internal.DataSource , modulePath , fullPath , requestedVersion string ) (status int , responseText string ) {
132
126
start := time .Now ()
133
127
defer func () {
@@ -158,7 +152,8 @@ func (s *Server) fetchAndPoll(ctx context.Context, ds internal.DataSource, modul
158
152
// finished, return an error letting the user to check back later. The
159
153
// worker will still be processing the modules in the background.
160
154
if ctx .Err () != nil {
161
- return http .StatusRequestTimeout , statusToResponseText [http .StatusRequestTimeout ]
155
+ return http .StatusRequestTimeout ,
156
+ fmt .Sprintf ("We're still working on “%s”. Come back in a few minutes!" , displayPath (fullPath , requestedVersion ))
162
157
}
163
158
return fetchRequestStatusAndResponseText (results , fullPath , requestedVersion )
164
159
}
@@ -224,30 +219,35 @@ func (s *Server) checkPossibleModulePaths(ctx context.Context, db *postgres.DB,
224
219
func fetchRequestStatusAndResponseText (results []* fetchResult , fullPath , requestedVersion string ) (int , string ) {
225
220
var moduleMatchingPathPrefix string
226
221
for _ , fr := range results {
222
+ switch fr .status {
227
223
// Results are in order of longest module path first. Once an
228
- // appropriate result is found, return. Otherwise, look at the next path.
229
- if fr .status == derrors .ToStatus (derrors .AlternativeModule ) {
224
+ // appropriate result is found, return. Otherwise, look at the next
225
+ // path.
226
+ case http .StatusOK :
227
+ return fr .status , ""
228
+ case http .StatusInternalServerError :
229
+ return fr .status , "Oops! Something went wrong."
230
+ case derrors .ToStatus (derrors .AlternativeModule ):
231
+ // TODO(https://golang.org/issue/40306): Make the canonical module
232
+ // path a clickable link.
230
233
return http .StatusSeeOther ,
231
- // TODO(https://golang.org/issue/40306): Make the canonical module path a clickable link.
232
- fmt .Sprintf ("“%s” is not a valid path. Were you looking for “%s”?" ,
234
+ fmt .Sprintf ("“%s” is not a valid package or module. Were you looking for “%s”?" ,
233
235
displayPath (fullPath , requestedVersion ), fr .goModPath )
234
236
}
235
- if responseText , ok := statusToResponseText [fr .status ]; ok {
236
- return fr .status , responseText
237
- }
237
+
238
+ // A module was found for a prefix of the path, but the path did not exist
239
+ // in that module. Note the longest possible modulePath in this case, and
240
+ // let the user know that it exists. For example, if the request was for
241
+ // github.com/hashicorp/vault/@master/api, github.com/hashicorp/vault/api
242
+ // does not exist at master, but it does in older versions of
243
+ // github.com/hashicorp/vault.
238
244
if errors .Is (fr .err , errPathDoesNotExistInModule ) && moduleMatchingPathPrefix == "" {
239
- // A module was found for a prefix of the path, but the path did
240
- // not exist in that module. Note the longest possible modulePath in
241
- // this case, and let the user know that it exists. For example, if
242
- // the request was for github.com/hashicorp/vault/@master/api,
243
- // github.com/hashicorp/vault/api does not exist at master, but it
244
- // does in older versions of github.com/hashicorp/vault.
245
245
moduleMatchingPathPrefix = fr .modulePath
246
246
}
247
247
}
248
248
if moduleMatchingPathPrefix != "" {
249
+ // TODO(https://golang.org/issue/40306): Make the link clickable.
249
250
return http .StatusNotFound ,
250
- // TODO(https://golang.org/issue/40306): Make the link clickable.
251
251
fmt .Sprintf ("Package “%s” could not be found, but you can view module “%s” at https://pkg.go.dev/mod/%s." ,
252
252
displayPath (fullPath , requestedVersion ),
253
253
displayPath (moduleMatchingPathPrefix , requestedVersion ),
0 commit comments