mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-06-06 19:16:19 +00:00
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m23s
- Updated payment verification logic in `actions/payment.ts` to remove unused code and improve clarity. - Enhanced `DevicesToPay` component to handle separate states for wallet and transfer payment verification. - Introduced a new `GetMacAccordion` component to guide users on finding their MAC addresses. - Created a reusable accordion component in `ui/accordion.tsx` for better UI consistency. - Integrated the MAC address guide into the device addition dialog. - Updated Tailwind CSS configuration to include animations for the accordion component. - Added Radix UI Accordion dependency to package.json and package-lock.json. - Improved error handling in API response utility to log unauthorized responses.
40 lines
931 B
TypeScript
40 lines
931 B
TypeScript
export async function tryCatch<T, E = Error>(promise: T | Promise<T>) {
|
|
try {
|
|
const data = await promise;
|
|
return [null, data] as const;
|
|
} catch (error) {
|
|
return [error as E, null] as const;
|
|
}
|
|
}
|
|
|
|
export async function handleApiResponse<T>(
|
|
response: Response,
|
|
fnName?: string,
|
|
) {
|
|
const responseData = await response.json();
|
|
if (response.status === 401) {
|
|
console.log('response data', responseData)
|
|
throw new Error("UNAUTHORIZED");
|
|
}
|
|
|
|
if (response.status === 403) {
|
|
throw new Error(
|
|
responseData.message ||
|
|
"Forbidden; you do not have permission to access this resource.",
|
|
);
|
|
}
|
|
|
|
if (response.status === 429) {
|
|
throw new Error(
|
|
responseData.message || "Too many requests; please try again later.",
|
|
);
|
|
}
|
|
|
|
if (!response.ok) {
|
|
console.log(`API Error Response from ${fnName}:`, responseData);
|
|
throw new Error(responseData.message || "Something went wrong.");
|
|
}
|
|
|
|
return responseData as T;
|
|
}
|