Skip to content

Commit 3d85bd4

Browse files
committed
fix: fix not checking the return type in service.ts in api domain
1 parent a28346e commit 3d85bd4

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

backend/src/api/service.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import * as db from "./db";
22
import crypto from "node:crypto";
33
import { ApiKey, Editor } from "./validation";
44
import { UserNotFound } from "@/auth/errors";
5-
import { ApiGenerationAfterAttempts } from "./errors";
5+
import {
6+
ApiGenerationAfterAttempts,
7+
ApiMetadataAlreadySet,
8+
ApiNotFound,
9+
} from "./errors";
610
import { DBError } from "@/pool";
711
import pool from "@/pool";
12+
import { AppError } from "@/utils/error";
813

914
const ATTEMPTS = 3;
1015

@@ -37,11 +42,21 @@ const setApiMetadata = async (
3742
editor: Editor,
3843
machine_name: string,
3944
os: string
40-
): Promise<void | UserNotFound> => {
45+
): Promise<void | UserNotFound | ApiMetadataAlreadySet | ApiNotFound> => {
4146
const client = await pool.connect();
4247
try {
4348
await client.query("begin transaction");
44-
await db.setAPIMetadata(client, api_key, editor, machine_name, os);
49+
const res = await db.setAPIMetadata(
50+
client,
51+
api_key,
52+
editor,
53+
machine_name,
54+
os
55+
);
56+
if (res instanceof AppError) {
57+
await client.query("rollback");
58+
return res;
59+
}
4560
await client.query("commit");
4661
} catch (err) {
4762
await client.query("rollback");

0 commit comments

Comments
 (0)