Skip to content

Commit

Permalink
Soft errors on invalid objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Nov 28, 2023
1 parent e1e915f commit 061ec50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 4 additions & 1 deletion apps/worker/src/jobs/generateBottleDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export default async function ({ bottleId }: { bottleId: number }) {
const bottle = await db.query.bottles.findFirst({
where: (bottles, { eq }) => eq(bottles.id, bottleId),
});
if (!bottle) throw new Error("Unknown bottle");
if (!bottle) {
logError(`Unknown bottle: ${bottleId}`);
return;
}
const result = await generateBottleDetails(bottle);

if (!result) return;
Expand Down
7 changes: 5 additions & 2 deletions apps/worker/src/jobs/generateEntityDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { db } from "@peated/server/db";
import type { Entity } from "@peated/server/db/schema";
import { changes, entities } from "@peated/server/db/schema";
import { arraysEqual } from "@peated/server/lib/equals";
import { logError } from "@peated/server/lib/log";
import { CountryEnum, EntityTypeEnum } from "@peated/server/schemas";
import { eq } from "drizzle-orm";
import { z } from "zod";

import config from "~/config";
import { getStructuredResponse } from "~/lib/openai";

Expand Down Expand Up @@ -93,7 +93,10 @@ export default async ({ entityId }: { entityId: number }) => {
const entity = await db.query.entities.findFirst({
where: (entities, { eq }) => eq(entities.id, entityId),
});
if (!entity) throw new Error("Unknown entity");
if (!entity) {
logError(`Unknown entity: ${entityId}`);
return;
}
const result = await generateEntityDetails(entity);

if (!result) return;
Expand Down
6 changes: 4 additions & 2 deletions apps/worker/src/jobs/notifyDiscordOnTasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export default async function ({ tastingId }: { tastingId: number }) {
bottle: true,
},
});
if (!tasting) throw new Error("Unknown tasting");

if (!tasting) {
logError(`Unknown tasting: ${tastingId}`);
return;
}
const fields = [];
if (tasting.rating !== null)
fields.push({
Expand Down

0 comments on commit 061ec50

Please sign in to comment.