Crud create and variant category

This commit is contained in:
hamid zarghami
2025-09-21 14:30:13 +03:30
parent 1457afce0b
commit f731f8f73d
23 changed files with 903 additions and 29 deletions
+9
View File
@@ -18,3 +18,12 @@ export type ErrorType = Error & {
};
};
};
export interface IGeneralError {
status: number;
success: boolean;
error: {
message: string;
details: string[];
};
}
+13
View File
@@ -1,4 +1,5 @@
import { twMerge } from "tailwind-merge";
import type { IGeneralError } from "./types";
/**
* Concatenates truthy classes into a space-separated string.
@@ -9,3 +10,15 @@ import { twMerge } from "tailwind-merge";
export const clx = (...classes: (string | boolean | undefined)[]): string => {
return twMerge(classes.filter(Boolean).join(" "));
};
export const extractErrorMessage = (
error: Error | unknown,
fallbackMessage: string = "خطایی رخ داده است"
): string => {
try {
const axiosError = error as { response?: { data: IGeneralError } };
return axiosError?.response?.data?.error?.details?.[0] || fallbackMessage;
} catch {
return fallbackMessage;
}
};