fix(frontend): localize agent creation errors
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
"API": {
|
||||
"SUCCESS_MESSAGE": "Agent added successfully",
|
||||
"EXIST_MESSAGE": "Agent email already in use, Please try another email address",
|
||||
"LIMIT_MESSAGE": "Agent limit reached. Please upgrade your plan or add more seats.",
|
||||
"ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"API": {
|
||||
"SUCCESS_MESSAGE": "添加客服成功",
|
||||
"EXIST_MESSAGE": "该邮箱已被注册,请输入新的电子邮箱",
|
||||
"LIMIT_MESSAGE": "客服数量已达到上限,请升级套餐或增加客服名额",
|
||||
"ERROR_MESSAGE": "无法连接服务器,请稍后再试"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -90,23 +90,19 @@ const addAgent = async () => {
|
||||
emit('close');
|
||||
}
|
||||
} catch (error) {
|
||||
const {
|
||||
response: {
|
||||
data: {
|
||||
error: errorResponse = '',
|
||||
attributes: attributes = [],
|
||||
message: attrError = '',
|
||||
} = {},
|
||||
} = {},
|
||||
} = error;
|
||||
const status = error?.response?.status;
|
||||
const data = error?.response?.data;
|
||||
const attributes = data?.attributes || [];
|
||||
|
||||
let errorMessage = '';
|
||||
if (error?.response?.status === 422 && !attributes.includes('base')) {
|
||||
errorMessage = t('AGENT_MGMT.ADD.API.EXIST_MESSAGE');
|
||||
if (status === 422 && !attributes.includes('base')) {
|
||||
useAlert(t('AGENT_MGMT.ADD.API.EXIST_MESSAGE'));
|
||||
} else if (status === 402 || data?.error?.code === 'PAYMENT_REQUIRED') {
|
||||
useAlert(t('AGENT_MGMT.ADD.API.LIMIT_MESSAGE'));
|
||||
} else {
|
||||
errorMessage = t('AGENT_MGMT.ADD.API.ERROR_MESSAGE');
|
||||
// Never pass the structured API error object to the toast. It renders as
|
||||
// raw JSON and the backend message is not localized.
|
||||
useAlert(t('AGENT_MGMT.ADD.API.ERROR_MESSAGE'));
|
||||
}
|
||||
useAlert(errorResponse || attrError || errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user