将所有throw new Error改成console.error加return的方式

master
LiuJiaNan 2025-12-20 16:42:46 +08:00
parent b04cc6bae3
commit 68a24253e9
11 changed files with 98 additions and 49 deletions

View File

@ -18,8 +18,10 @@ function DictionaryCascader(props) {
const [treeData, setTreeData] = useState([]); const [treeData, setTreeData] = useState([]);
const getData = async () => { const getData = async () => {
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中"); console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
return;
}
setTreeData([]); setTreeData([]);
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });

View File

@ -18,8 +18,10 @@ function DictionaryLeftTree(props) {
const [treeData, setTreeData] = useState([]); const [treeData, setTreeData] = useState([]);
const getData = async () => { const getData = async () => {
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中"); console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
return;
}
setTreeData([]); setTreeData([]);
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });

View File

@ -18,8 +18,10 @@ function DictionarySelect(props) {
const [data, setData] = useState([]); const [data, setData] = useState([]);
const getData = async () => { const getData = async () => {
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中"); console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
return;
}
setData([]); setData([]);
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });

View File

@ -18,8 +18,10 @@ function DictionarySelectTree(props) {
const [treeData, setTreeData] = useState([]); const [treeData, setTreeData] = useState([]);
const getData = async () => { const getData = async () => {
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
throw new Error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中"); console.error("传入的 appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
return;
}
setTreeData([]); setTreeData([]);
const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue }); const { data } = await request("/config/dict-trees/list/by/dictValues", "get", { appKey, dictValue });

View File

@ -12,8 +12,10 @@ function useDeleteFile(returnType = "object") {
// 删除文件 // 删除文件
const deleteFile = (options) => { const deleteFile = (options) => {
if (!options) if (!options) {
throw new Error("请传入 options"); console.error("请传入 options");
return;
}
// 增加请求数量并设置loading状态 // 增加请求数量并设置loading状态
requestCount++; requestCount++;
@ -24,10 +26,14 @@ function useDeleteFile(returnType = "object") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { files = [], single = true } = options; const { files = [], single = true } = options;
if (!files) if (!files) {
throw new Error("请传入 files"); console.error("请传入 files");
if (!Array.isArray(files)) return;
throw new Error("请传入有效的 files"); }
if (!Array.isArray(files)) {
console.error("请传入有效的 files");
return;
}
// 如果没有文件则直接返回 // 如果没有文件则直接返回
if (files.length === 0) { if (files.length === 0) {

View File

@ -13,8 +13,10 @@ function useDictionary(returnType = "object") {
// 获取数据字典 // 获取数据字典
const getDictionary = (options) => { const getDictionary = (options) => {
if (!options) if (!options) {
throw new Error("请传入 options"); console.error("请传入 options");
return;
}
// 增加请求数量并设置loading状态 // 增加请求数量并设置loading状态
requestCount++; requestCount++;
@ -25,10 +27,14 @@ function useDictionary(returnType = "object") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options; const { appKey = DICTIONARY_APP_KEY_ENUM.DEFAULT, dictValue } = options;
if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) if (!Object.values(DICTIONARY_APP_KEY_ENUM).includes(appKey)) {
throw new Error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中"); console.error("传入的 options.appKey 不在 DICTIONARY_APP_KEY_ENUM 中");
if (!dictValue) return;
throw new Error("请传入 options.dictValue"); }
if (!dictValue) {
console.error("请传入 options.dictValue");
return;
}
// 发送请求 // 发送请求
request( request(

View File

@ -38,7 +38,8 @@ export default function useDownloadBlob(returnType = "object") {
}) })
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
throw new Error("Network response was not ok"); console.error("网络响应异常");
return;
} }
return response.blob(); return response.blob();
}) })

View File

@ -20,8 +20,10 @@ export default function useDownloadFile(returnType = "object") {
} }
const { url, name: fileName } = options; const { url, name: fileName } = options;
if (!url) if (!url) {
throw new Error("请传入 url"); console.error("请传入 url");
return;
}
Modal.confirm({ Modal.confirm({
title: "提示", title: "提示",

View File

@ -14,8 +14,10 @@ function useGetFile(returnType = "object") {
// 获取文件 // 获取文件
const getFile = (options) => { const getFile = (options) => {
if (!options) if (!options) {
throw new Error("请传入 options"); console.error("请传入 options");
return;
}
// 增加请求数量并设置loading状态 // 增加请求数量并设置loading状态
requestCount++; requestCount++;
@ -26,15 +28,21 @@ function useGetFile(returnType = "object") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { eqType, eqForeignKey } = options; const { eqType, eqForeignKey } = options;
if (!eqType) if (!eqType) {
throw new Error("请传入 options.eqType"); console.error("请传入 options.eqType");
return;
}
// 检查eqType是否在UPLOAD_FILE_TYPE_ENUM中 // 检查eqType是否在UPLOAD_FILE_TYPE_ENUM中
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType)) if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(eqType)) {
throw new Error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中"); console.error("传入的 eqType 不在 UPLOAD_FILE_TYPE_ENUM 中");
return;
}
if (eqForeignKey === undefined || eqForeignKey === null) if (eqForeignKey === undefined || eqForeignKey === null) {
throw new Error("请传入 options.eqForeignKey"); console.error("请传入 options.eqForeignKey");
return;
}
// 发送请求 // 发送请求
request( request(

View File

@ -44,8 +44,10 @@ function getService(service, getExtraParams = {}, transform, usePermission) {
* 自定义 useTable继承 ahooks useAntdTable根据需求进行扩展 * 自定义 useTable继承 ahooks useAntdTable根据需求进行扩展
*/ */
function useTable(service, options) { function useTable(service, options) {
if (!service) if (!service) {
throw new Error("请传入 service"); console.error("请传入 service")
return;
}
// 获取额外参数和转换函数 // 获取额外参数和转换函数
const { params: extraParams, transform, ...restOptions } = options || {}; const { params: extraParams, transform, ...restOptions } = options || {};

View File

@ -13,8 +13,10 @@ function useUploadFile(returnType = "object") {
// 上传文件 // 上传文件
const uploadFile = (options) => { const uploadFile = (options) => {
if (!options) if (!options) {
throw new Error("请传入 options"); console.error("请传入 options");
return;
}
// 增加请求数量并设置loading状态 // 增加请求数量并设置loading状态
requestCount++; requestCount++;
@ -25,28 +27,42 @@ function useUploadFile(returnType = "object") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const { files = [], single = true, params } = options; const { files = [], single = true, params } = options;
if (!files) if (!files) {
throw new Error("请传入 files"); console.error("请传入 files");
if (!Array.isArray(files)) return;
throw new Error("请传入有效的 files"); }
if (!params) if (!Array.isArray(files)) {
throw new Error("请传入 options.params"); console.error("请传入有效的 files");
if (!params.type) return;
throw new Error("请传入 options.params.type"); }
if (!params) {
console.error("请传入 options.params");
return;
}
if (!params.type) {
console.error("请传入 options.params.type");
return;
}
// 检查type是否在UPLOAD_FILE_TYPE_ENUM中 // 检查type是否在UPLOAD_FILE_TYPE_ENUM中
if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type)) if (!Object.values(UPLOAD_FILE_TYPE_ENUM).includes(params.type)) {
throw new Error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中"); console.error("传入的 type 不在 UPLOAD_FILE_TYPE_ENUM 中");
return;
}
// 根据type获取对应的path // 根据type获取对应的path
const path = UPLOAD_FILE_PATH_ENUM[params.type]; const path = UPLOAD_FILE_PATH_ENUM[params.type];
if (!path) if (!path) {
throw new Error(`未找到 type ${params.type} 对应的 path `); console.error(`未找到 type ${params.type} 对应的 path `);
return;
}
// 当single为false时foreignKey是必需的 // 当single为false时foreignKey是必需的
if (!single) { if (!single) {
if (!params.hasOwnProperty("foreignKey")) if (!params.hasOwnProperty("foreignKey")) {
throw new Error("请传入 options.params.foreignKey"); console.error("请传入 options.params.foreignKey");
return;
}
// 如果 foreignKey 是 undefined设置默认值为空字符串 // 如果 foreignKey 是 undefined设置默认值为空字符串
if (params.foreignKey === undefined || params.foreignKey === null) if (params.foreignKey === undefined || params.foreignKey === null)
params.foreignKey = ""; params.foreignKey = "";