Refactor code
This commit is contained in:
@ -2,15 +2,6 @@
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Server action
|
||||
* Forwards a multipart/form-data request (payload + files[])
|
||||
* from the public app to the admin app's public commissions endpoint.
|
||||
*
|
||||
* Server-only env required:
|
||||
* ADMIN_URL=https://admin.domain.com
|
||||
*/
|
||||
|
||||
const submitPayloadSchema = z.object({
|
||||
typeId: z.string().optional().nullable(),
|
||||
optionId: z.string().optional().nullable(),
|
||||
@ -36,7 +27,6 @@ export async function submitCommissionRequest(input: {
|
||||
const payload = submitPayloadSchema.parse(input.payload);
|
||||
const files = input.files ?? [];
|
||||
|
||||
// Optional safety limits
|
||||
const MAX_FILES = 10;
|
||||
const MAX_BYTES_EACH = 10 * 1024 * 1024; // 10MB
|
||||
|
||||
@ -70,7 +60,6 @@ export async function submitCommissionRequest(input: {
|
||||
const raw = await res.text().catch(() => "");
|
||||
const statusLine = `${res.status} ${res.statusText || ""}`.trim();
|
||||
|
||||
// Show something useful even if raw is empty
|
||||
let message = `Admin API error: ${statusLine}`;
|
||||
|
||||
if (raw) {
|
||||
@ -87,12 +76,9 @@ export async function submitCommissionRequest(input: {
|
||||
}
|
||||
}
|
||||
|
||||
// Log full body server-side for debugging (safe; this is server-only)
|
||||
console.error("[submitCommissionRequest] upstream error", { statusLine, raw });
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
// Expected response: { id: string; createdAt: string }
|
||||
return (await res.json()) as { id: string; createdAt: string };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user