|
|
@@ -90,7 +90,15 @@ const SalaryManagement: React.FC = () => {
|
|
|
const createMutation = useMutation({
|
|
|
mutationFn: async (data: CreateSalaryRequest) => {
|
|
|
const res = await salaryClientManager.get().create.$post({ json: data });
|
|
|
- if (res.status !== 200) throw new Error('创建薪资失败');
|
|
|
+ if (res.status !== 200) {
|
|
|
+ // 尝试从响应中提取错误信息
|
|
|
+ try {
|
|
|
+ const errorData = await res.json();
|
|
|
+ throw new Error(errorData.message || '创建薪资失败');
|
|
|
+ } catch {
|
|
|
+ throw new Error('创建薪资失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
return await res.json();
|
|
|
},
|
|
|
onSuccess: () => {
|
|
|
@@ -112,7 +120,15 @@ const SalaryManagement: React.FC = () => {
|
|
|
param: { id: data.id! },
|
|
|
json: data
|
|
|
});
|
|
|
- if (res.status !== 200) throw new Error('更新薪资失败');
|
|
|
+ if (res.status !== 200) {
|
|
|
+ // 尝试从响应中提取错误信息
|
|
|
+ try {
|
|
|
+ const errorData = await res.json();
|
|
|
+ throw new Error(errorData.message || '更新薪资失败');
|
|
|
+ } catch {
|
|
|
+ throw new Error('更新薪资失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
return await res.json();
|
|
|
},
|
|
|
onSuccess: () => {
|
|
|
@@ -129,7 +145,15 @@ const SalaryManagement: React.FC = () => {
|
|
|
const deleteMutation = useMutation({
|
|
|
mutationFn: async (id: number) => {
|
|
|
const res = await salaryClientManager.get().delete[':id']['$delete']({ param: { id } });
|
|
|
- if (res.status !== 200) throw new Error('删除薪资失败');
|
|
|
+ if (res.status !== 200) {
|
|
|
+ // 尝试从响应中提取错误信息
|
|
|
+ try {
|
|
|
+ const errorData = await res.json();
|
|
|
+ throw new Error(errorData.message || '删除薪资失败');
|
|
|
+ } catch {
|
|
|
+ throw new Error('删除薪资失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
return await res.json();
|
|
|
},
|
|
|
onSuccess: () => {
|