🩹 (simple-fix) fix handler error request

This commit is contained in:
2025-10-07 11:59:22 +07:00
parent 171862aa3a
commit f13f1ccaf1
5 changed files with 51 additions and 17 deletions

View File

@ -2,9 +2,15 @@
import { HTTPError } from "ky";
export type CallApiErrorHandler = {
success?: boolean;
status?: number;
text?: { message?: string };
};
export const apiErrorHandler = async (
error: unknown,
safeFail: boolean = false
safeFail?: CallApiErrorHandler
) => {
if (error instanceof HTTPError) {
return {
@ -16,9 +22,11 @@ export const apiErrorHandler = async (
if (safeFail) {
return {
success: false,
status: 500,
text: { message: "An unexpected error occurred" },
success: safeFail.success || false,
status: safeFail.status || 500,
text: {
message: safeFail.text?.message || "An unexpected error occurred",
},
};
} else {
throw error;

View File

@ -0,0 +1,7 @@
export type ServerRequestCallback = {
success: boolean;
status: number;
text: { message: string };
data?: any;
error?: unknown;
};