MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / GetFeature

Method GetFeature

backend/pkg/httpserver/get_feature.go:74–120  ·  view source on GitHub ↗

GetFeature implements backend.StrictServerInterface. nolint: revive, ireturn // Name generated from openapi

(
	ctx context.Context,
	request backend.GetFeatureRequestObject,
)

Source from the content-addressed store, hash-verified

72// GetFeature implements backend.StrictServerInterface.
73// nolint: revive, ireturn // Name generated from openapi
74func (s *Server) GetFeature(
75 ctx context.Context,
76 request backend.GetFeatureRequestObject,
77) (backend.GetFeatureResponseObject, error) {
78 var cachedResponse backend.GetFeature200JSONResponse
79 found := s.operationResponseCaches.getFeatureCache.Lookup(ctx, request, &cachedResponse)
80 if found {
81 return cachedResponse, nil
82 }
83 result, err := s.wptMetricsStorer.GetFeature(ctx, request.FeatureId,
84 getWPTMetricViewOrDefault(request.Params.WptMetricView),
85 backendtypes.DefaultBrowsers(),
86 )
87 if err != nil {
88 if errors.Is(err, gcpspanner.ErrQueryReturnedNoResults) {
89 return backend.GetFeature404JSONResponse{
90 Code: http.StatusNotFound,
91 Message: fmt.Sprintf("feature id %s is not found", request.FeatureId),
92 }, nil
93 }
94 // Catch all for all other errors.
95 slog.ErrorContext(ctx, "unable to get feature", "error", err)
96
97 return backend.GetFeature500JSONResponse{
98 Code: 500,
99 Message: "unable to get feature",
100 }, nil
101 }
102
103 v := &GetFeatureResultVisitor{
104 resp: nil,
105 getFeatureCache: s.operationResponseCaches.getFeatureCache,
106 request: request,
107 baseURL: s.baseURL,
108 }
109 err = result.Visit(ctx, v)
110 if err != nil {
111 slog.ErrorContext(ctx, "unable to determine if feature is regular, split, or moved", "error", err)
112
113 return backend.GetFeature500JSONResponse{
114 Code: http.StatusInternalServerError,
115 Message: "unable to determine if feature is regular, split, or moved",
116 }, nil
117 }
118
119 return v.resp, nil
120}

Callers

nothing calls this directly

Calls 4

LookupMethod · 0.80
GetFeatureMethod · 0.65
VisitMethod · 0.65

Tested by

no test coverage detected