ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Errorwhenindoubt (#444)

* 404 on missing params it is time

* rror on params/originhash notfound/empty

* bad rebase

---------

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
5460c829 b6ad96b9

+8 -23
+5 -13
internal/recipes/server.go
··· 184 184 loadWG.Wait() 185 185 186 186 if recipe.OriginHash == "" { 187 - slog.WarnContext(ctx, "recipe missing origin hash Probably and old recipe", "hash", hash) 188 - p := DefaultParams(&locations.Location{ 189 - ID: "", 190 - Name: "Unknown Location", 191 - }, time.Now()) 192 - FormatRecipeHTML(ctx, p, *recipe, signedIn, hasRecipeImage, thread, feedback, wineRecommendation, w) 187 + slog.ErrorContext(ctx, "No origin hash for recipe", "hash", hash, "error", err) 188 + http.Error(w, "recipe not found or expired", http.StatusInternalServerError) 193 189 return 194 190 } 195 191 // we didn't go back and update old recipes's with new hash so have to handle that here. Could still backfill ··· 200 196 } 201 197 p, err := s.ParamsFromCache(ctx, recipe.OriginHash) 202 198 if err != nil { 203 - slog.ErrorContext(ctx, "failed to load params for hash", "hash", recipe.OriginHash, "error", err) 204 - // http.Error(w, "recipe not found or expired", http.StatusNotFound) 205 - // return 206 - p = DefaultParams(&locations.Location{ 207 - ID: "", 208 - Name: "Unknown Location", 209 - }, time.Now()) 199 + slog.ErrorContext(ctx, "failed to load params for hash", "origin hash", recipe.OriginHash, "hash", hash, "error", err) 200 + http.Error(w, "recipe not found or expired", http.StatusInternalServerError) 201 + return 210 202 } 211 203 212 204 if p.ConversationID == "" {
+3 -10
internal/recipes/server_test.go
··· 386 386 } 387 387 } 388 388 389 - func TestHandleSingle_LegacyOriginHashDoesNotFailWhenParamsMissing(t *testing.T) { 389 + func TestHandleSingle_LegacyOriginHashFailWhenParamsMissing(t *testing.T) { 390 390 cacheStore := cache.NewFileCache(filepath.Join(t.TempDir(), "cache")) 391 391 s := newTestServer(t, withTestCache(cacheStore)) 392 392 ··· 419 419 420 420 s.handleSingle(rr, req) 421 421 422 - if rr.Code != http.StatusOK { 423 - t.Fatalf("expected status %d, got %d", http.StatusOK, rr.Code) 424 - } 425 - body := rr.Body.String() 426 - if !strings.Contains(body, "/recipes?h="+canonicalHash) { 427 - t.Fatalf("expected canonical back-link hash %q in response body: %s", canonicalHash, body) 428 - } 429 - if !strings.Contains(body, "Unknown Location") { 430 - t.Fatalf("expected fallback params rendering with Unknown Location, body: %s", body) 422 + if rr.Code != http.StatusInternalServerError { 423 + t.Fatalf("expected status %d, got %d", http.StatusInternalServerError, rr.Code) 431 424 } 432 425 } 433 426