|
8 | 8 | "context"
|
9 | 9 | "errors"
|
10 | 10 | "fmt"
|
11 |
| - "html/template" |
12 | 11 | "net/http"
|
13 | 12 | "strings"
|
14 | 13 |
|
@@ -80,16 +79,7 @@ func (s *Server) servePackagePage(w http.ResponseWriter, r *http.Request, pkgPat
|
80 | 79 | }
|
81 | 80 | _, err = s.ds.GetPackage(ctx, pkgPath, modulePath, internal.LatestVersion)
|
82 | 81 | if err == nil {
|
83 |
| - return &serverError{ |
84 |
| - status: http.StatusNotFound, |
85 |
| - epage: &errorPage{ |
86 |
| - Message: fmt.Sprintf("Package %s@%s is not available.", pkgPath, displayVersion(version, modulePath)), |
87 |
| - SecondaryMessage: template.HTML( |
88 |
| - fmt.Sprintf(`There are other versions of this package that are! To view them, `+ |
89 |
| - `<a href="/%s?tab=versions">click here</a>.`, |
90 |
| - pkgPath)), |
91 |
| - }, |
92 |
| - } |
| 82 | + return pathFoundAtLatestError(ctx, "package", pkgPath, version) |
93 | 83 | }
|
94 | 84 | if !errors.Is(err, derrors.NotFound) {
|
95 | 85 | // Unlike the error handling for GetDirectory above, we don't serve an
|
@@ -184,23 +174,13 @@ func (s *Server) servePackagePageNew(w http.ResponseWriter, r *http.Request, ful
|
184 | 174 | }
|
185 | 175 | // We couldn't find a path at the given version, but if there's one at the latest version
|
186 | 176 | // we can provide a link to it.
|
187 |
| - modulePath, version, _, err = s.ds.GetPathInfo(ctx, fullPath, inModulePath, internal.LatestVersion) |
188 |
| - if err != nil { |
| 177 | + if _, _, _, err = s.ds.GetPathInfo(ctx, fullPath, inModulePath, internal.LatestVersion); err != nil { |
189 | 178 | if errors.Is(err, derrors.NotFound) {
|
190 | 179 | return pathNotFoundError(ctx, "package", fullPath, inVersion)
|
191 | 180 | }
|
192 | 181 | return err
|
193 | 182 | }
|
194 |
| - return &serverError{ |
195 |
| - status: http.StatusNotFound, |
196 |
| - epage: &errorPage{ |
197 |
| - Message: fmt.Sprintf("Package %s@%s is not available.", fullPath, displayVersion(version, modulePath)), |
198 |
| - SecondaryMessage: template.HTML( |
199 |
| - fmt.Sprintf(`There are other versions of this package that are! To view them, `+ |
200 |
| - `<a href="/%s?tab=versions">click here</a>.`, |
201 |
| - fullPath)), |
202 |
| - }, |
203 |
| - } |
| 183 | + return pathFoundAtLatestError(ctx, "package", fullPath, inVersion) |
204 | 184 | }
|
205 | 185 | vdir, err := s.ds.GetDirectoryNew(ctx, fullPath, modulePath, version)
|
206 | 186 | if err != nil {
|
|
0 commit comments