From bd6b1e7e062073a1f20e2da680b8d53bc432f770 Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Tue, 20 Jun 2023 19:10:50 +0200 Subject: [PATCH 1/2] fix(cors): 400 res on missing url --- cors-proxy/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cors-proxy/src/index.ts b/cors-proxy/src/index.ts index 56125eb8..29d7af25 100644 --- a/cors-proxy/src/index.ts +++ b/cors-proxy/src/index.ts @@ -64,7 +64,10 @@ export default { const apiUrl = url.searchParams.get(QUERYSTRING_KEY); if (apiUrl == null) { - return new Response(`Missing GET parameter: ${QUERYSTRING_KEY}`); + return new Response(`Missing GET parameter: ${QUERYSTRING_KEY}`, { + status: 400, + statusText: `Bad Request: ${QUERYSTRING_KEY} param undefined`, + }); } // Rewrite request to point to API URL. This also makes the request mutable From ee89e21334fe35b3a9f7f8688ea2d565ecb79747 Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Tue, 20 Jun 2023 19:43:26 +0200 Subject: [PATCH 2/2] feat(canvas): error handling and toast --- frontend/components/hypercert-create.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/components/hypercert-create.tsx b/frontend/components/hypercert-create.tsx index 6fe25ff1..a4f0e91c 100644 --- a/frontend/components/hypercert-create.tsx +++ b/frontend/components/hypercert-create.tsx @@ -379,6 +379,12 @@ export function HypercertCreateForm(props: HypercertCreateFormProps) { } const image = await exportAsImage(IMAGE_SELECTOR); + + if (!image) { + setSubmitting(false); + return; + } + const metaData = formatValuesToMetaData( values, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -516,7 +522,18 @@ const exportAsImage = async (id: string) => { //useCORS: true, proxy: "https://cors-proxy.hypercerts.workers.dev/", imageTimeout: 0, + }).catch((e) => { + toast("Error loading hypercert image . Please contact the team.", { + type: "error", + }); + console.error("Error exporting image: ", e); + return undefined; }); + + if (!canvas) { + return undefined; + } + const image = canvas.toDataURL("image/png", 1.0); return image; };