Skip to content

Commit 82c1afb

Browse files
committed
throw error if we can't persist the token
1 parent 09259be commit 82c1afb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/toolshed/routes/integrations/google-oauth/google-oauth.utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { OAuth2Client, Tokens } from "@cmd-johnson/oauth2-client";
2+
import { getLogger } from "@commontools/utils/logger";
23
import env from "@/env.ts";
34
import { runtime } from "@/index.ts";
45
import { Context } from "@hono/hono";
56
import { AuthSchema, Mutable, Schema } from "@commontools/runner";
6-
// Types
7+
8+
const logger = getLogger("google-oauth.utils");
79

810
export interface OAuth2Tokens {
911
accessToken: string;
@@ -186,12 +188,14 @@ export async function persistTokens(
186188
};
187189

188190
// Set the new tokens to the auth cell
189-
await authCell.runtime.editWithRetry((tx) => {
191+
const error = await authCell.runtime.editWithRetry((tx) => {
190192
authCell.withTx(tx).set(tokenData);
191193
});
194+
if (error) throw error;
192195

193196
return tokenData;
194197
} catch (error) {
198+
logger.error("Error persisting tokens", error);
195199
throw new Error(`Error persisting tokens: ${error}`);
196200
}
197201
}

0 commit comments

Comments
 (0)