Skip to content

Commit d5a9d33

Browse files
committed
WEB-108 Move wrapAction to utils
1 parent 4f81bfe commit d5a9d33

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/lib/documents/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
PublishVersionInput,
1414
Version,
1515
} from "../types";
16-
import { wrapAction } from "../wrap-action";
16+
import { wrapAction } from "../utils";
1717

1818
function assertNotArchived(doc: { archivedAt: Date | null }): void {
1919
if (doc.archivedAt !== null) {

src/lib/media/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
DeleteMediaInput,
1010
RenameInput,
1111
} from "../types";
12-
import { wrapAction } from "../wrap-action";
12+
import { wrapAction } from "../utils";
1313

1414
export async function uploadMediaAction(
1515
formData: FormData

src/lib/routes/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
DeleteRouteInput,
88
UpdateRouteInput,
99
} from "../types";
10-
import { wrapAction } from "../wrap-action";
10+
import { wrapAction } from "../utils";
1111

1212
const ROUTE_SEGMENT_RE = /^[a-z0-9_-]+$/;
1313

src/lib/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { clsx, type ClassValue } from "clsx"
22
import { twMerge } from "tailwind-merge"
3+
import type { ActionResult } from "./types";
34

45
export function cn(...inputs: ClassValue[]) {
56
return twMerge(clsx(inputs))
@@ -12,3 +13,16 @@ export function validateName(name: string): string {
1213
}
1314
return trimmed;
1415
}
16+
17+
export async function wrapAction<T>(
18+
fn: () => Promise<T>
19+
): Promise<ActionResult<T>> {
20+
try {
21+
return { success: true, data: await fn() };
22+
} catch (error) {
23+
return {
24+
success: false,
25+
error: error instanceof Error ? error.message : "Unknown error",
26+
};
27+
}
28+
}

src/lib/wrap-action.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)