Skip to content

Commit c6d0ccb

Browse files
committed
internal/frontend: improve error message for proxydatasource
When an endpoint is not supported by the proxydatasource, we now return a message letting the user know that is the case. Change-Id: I2c5cf3a03e8aa43d72c3599fc37c47da20756e9c Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/238977 Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent b4c53fb commit c6d0ccb

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

internal/frontend/details.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ func pathFoundAtLatestError(ctx context.Context, pathType, fullPath, version str
294294
}
295295
}
296296

297+
func proxydatasourceNotSupportedErr() error {
298+
return &serverError{
299+
status: http.StatusFailedDependency,
300+
epage: &errorPage{
301+
Message: "This page is not supported by the proxydatasource.",
302+
},
303+
}
304+
}
305+
297306
func parseStdLibURLPath(urlPath string) (path, version string, err error) {
298307
defer derrors.Wrap(&err, "parseStdLibURLPath(%q)", urlPath)
299308

internal/frontend/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (s *Server) stdlibPathForShortcut(ctx context.Context, shortcut string) (pa
193193
}
194194
db, ok := s.ds.(*postgres.DB)
195195
if !ok {
196-
return "", &serverError{status: http.StatusFailedDependency}
196+
return "", proxydatasourceNotSupportedErr()
197197
}
198198
matches, err := db.GetStdlibPathsWithSuffix(ctx, shortcut)
199199
if err != nil {

internal/frontend/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *Server) serveSearch(w http.ResponseWriter, r *http.Request) error {
106106
db, ok := s.ds.(*postgres.DB)
107107
if !ok {
108108
// The proxydatasource does not support the imported by page.
109-
return &serverError{status: http.StatusFailedDependency}
109+
return proxydatasourceNotSupportedErr()
110110
}
111111

112112
ctx := r.Context()

internal/frontend/tabs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func fetchDetailsForPackage(ctx context.Context, r *http.Request, tab string, ds
156156
db, ok := ds.(*postgres.DB)
157157
if !ok {
158158
// The proxydatasource does not support the imported by page.
159-
return nil, &serverError{status: http.StatusFailedDependency}
159+
return nil, proxydatasourceNotSupportedErr()
160160
}
161161
return fetchImportedByDetails(ctx, db, pkg.Path, pkg.ModulePath)
162162
case "licenses":
@@ -184,7 +184,7 @@ func fetchDetailsForVersionedDirectory(ctx context.Context, r *http.Request, tab
184184
db, ok := ds.(*postgres.DB)
185185
if !ok {
186186
// The proxydatasource does not support the imported by page.
187-
return nil, &serverError{status: http.StatusFailedDependency}
187+
return nil, proxydatasourceNotSupportedErr()
188188
}
189189
return fetchImportedByDetails(ctx, db, vdir.Path, vdir.ModulePath)
190190
case "licenses":

0 commit comments

Comments
 (0)