From f112371efa210dea7f235eaafadb4220ae92aeb5 Mon Sep 17 00:00:00 2001 From: Seven Date: Sun, 14 Dec 2025 20:40:17 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=20safeClient=20?= =?UTF-8?q?=E5=B0=81=E8=A3=85=20API=20=E8=B0=83=E7=94=A8=E5=B9=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 24 ++++++++++++++++++++++++ src/views/withdraw/index.vue | 15 ++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 16c0cd7..923ac73 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,5 +1,6 @@ import type { App } from "@riwa/api-types"; import { treaty } from "@elysiajs/eden"; +import { toastController } from "@ionic/vue"; const client = treaty(window.location.origin, { fetch: { @@ -7,4 +8,27 @@ const client = treaty(window.location.origin, { }, }); +export async function safeClient( + requestPromise: Promise<{ data: T; error: E | null }>, + options: { silent?: boolean } = {}, +) { + const { data, error } = await requestPromise; + + if (error) { + if (!options.silent) { + const toast = await toastController.create({ + message: typeof error === "string" ? error : "Request failed. Please try again.", + duration: 3000, + position: "bottom", + color: "danger", + }); + await toast.present(); + } + + throw error; + } + + return { data, error }; +} + export { client }; diff --git a/src/views/withdraw/index.vue b/src/views/withdraw/index.vue index 677d122..7d292d4 100644 --- a/src/views/withdraw/index.vue +++ b/src/views/withdraw/index.vue @@ -1,7 +1,7 @@