From 6365a701ba16eddbc4e5997f062437a1615896a9 Mon Sep 17 00:00:00 2001 From: i701 Date: Mon, 14 Apr 2025 01:05:07 +0500 Subject: [PATCH] feat: enhance error handling and improve API response management across components --- app/(dashboard)/devices/[deviceId]/page.tsx | 17 ++++-- components/auth/login-form.tsx | 3 +- components/auth/verify-otp-form.tsx | 8 ++- components/block-device-dialog.tsx | 16 ++--- components/client-error-message.tsx | 20 ++++--- components/devices-table.tsx | 9 ++- components/payments-table.tsx | 2 +- components/ui/app-sidebar.tsx | 4 +- components/ui/phone-input.tsx | 2 +- queries/devices.ts | 66 +++++++++++---------- utils/tryCatch.ts | 30 ++++++++++ 11 files changed, 111 insertions(+), 66 deletions(-) diff --git a/app/(dashboard)/devices/[deviceId]/page.tsx b/app/(dashboard)/devices/[deviceId]/page.tsx index bd6dfb8..c9a8f7c 100644 --- a/app/(dashboard)/devices/[deviceId]/page.tsx +++ b/app/(dashboard)/devices/[deviceId]/page.tsx @@ -1,8 +1,10 @@ import BlockDeviceDialog from "@/components/block-device-dialog"; +import ClientErrorMessage from "@/components/client-error-message"; import Search from "@/components/search"; import { Badge } from "@/components/ui/badge"; import { getDevice } from "@/queries/devices"; import { tryCatch } from "@/utils/tryCatch"; +import { redirect } from "next/navigation"; import React from "react"; export default async function DeviceDetails({ @@ -12,7 +14,15 @@ export default async function DeviceDetails({ }) { const deviceId = (await params)?.deviceId; const [error, device] = await tryCatch(getDevice({ deviceId: deviceId })); - if (error) return
{error.message}
; + if (error) { + // Handle specific actions for certain errors, but reuse the error message + if (error.message === "UNAUTHORIZED") { + redirect("/auth/signin"); + } else { + // For all other errors, display the error message directly + return ; + } + } if (!device) return null; return ( @@ -38,11 +48,6 @@ export default async function DeviceDetails({ ACTIVE

)} - -
{JSON.stringify(device.blocked, null, 2)}
diff --git a/components/auth/login-form.tsx b/components/auth/login-form.tsx index 9062dc7..4bdb163 100644 --- a/components/auth/login-form.tsx +++ b/components/auth/login-form.tsx @@ -15,7 +15,7 @@ export default function LoginForm() { return (
@@ -23,7 +23,6 @@ export default function LoginForm() {
-
-