(w http.ResponseWriter, r *http.Request)
| 28 | ) |
| 29 | |
| 30 | func (h *handler) GetPackageMetadata(w http.ResponseWriter, r *http.Request) { |
| 31 | ctx := r.Context() |
| 32 | info, ok := request.ArtifactInfoFrom(ctx).(npm2.ArtifactInfo) |
| 33 | if !ok { |
| 34 | log.Ctx(ctx).Error().Msg("Failed to get npm artifact info from context") |
| 35 | h.HandleErrors(r.Context(), []error{fmt.Errorf("failed to fetch npm artifact info from context")}, w) |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | response := h.controller.GetPackageMetadata(ctx, info) |
| 40 | |
| 41 | if !commons.IsEmpty(response.GetError()) { |
| 42 | if errors2.IsNotFound(response.GetError()) { |
| 43 | http.Error(w, response.GetError().Error(), http.StatusNotFound) |
| 44 | return |
| 45 | } |
| 46 | http.Error(w, response.GetError().Error(), http.StatusInternalServerError) |
| 47 | return |
| 48 | } |
| 49 | w.Header().Set("Content-Type", "application/json") |
| 50 | err := json.NewEncoder(w).Encode(response.PackageMetadata) |
| 51 | if err != nil { |
| 52 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 53 | return |
| 54 | } |
| 55 | } |
nothing calls this directly
no test coverage detected