Checkout: forward only the checkout fields, show clear errors, fix the contact form (#16)
build / test (push) Successful in 10s
build / build (push) Skipped

Co-authored-by: Michael Czechowski <mail@librete.ch>
This commit was merged in pull request #16.
This commit is contained in:
libretech authored and Michael Czechowski committed 2026-10-15 10:31:57 +02:00
1 parent d5dd109c63
commit d46bc9380e
29 files changed
+1108 -71

No files matched your search

+17
View File
@@ -1,3 +1,5 @@
import { cmsErrorLogLine, shopErrorFromCms } from "./cmsError";
/**
* Server-side CMS API utility.
* Use this for direct CMS access during SSR.
@@ -15,3 +17,18 @@ export async function fetchCms<T>(endpoint: string, options: Parameters<typeof $
}
});
}
/**
* fetchCms for a route that forwards the browser's request to the CMS: a CMS error answers the browser with the CMS's status
* and the safe fields of its error (cmsError.ts), instead of an unhandled error, whose message and data Nitro hides.
*/
export async function forwardToCms<T>(endpoint: string, options: Parameters<typeof $fetch>[1] = {}): Promise<T> {
try {
return await fetchCms<T>(endpoint, options);
} catch (error) {
const shopError = shopErrorFromCms(error);
if (!shopError) throw error;
if (shopError.statusCode >= 500) console.error(cmsErrorLogLine(String(options.method ?? "GET"), endpoint, shopError));
throw createError(shopError);
}
}