修复设置通知错误时提示不清晰

This commit is contained in:
whyour 2023-05-24 23:37:44 +08:00
parent ca150dc6a6
commit 826f214f0f
4 changed files with 94 additions and 24 deletions

View File

@ -7,7 +7,7 @@ export default defineConfig({
antd: {}, antd: {},
outputPath: 'static/dist', outputPath: 'static/dist',
fastRefresh: true, fastRefresh: true,
favicons: ['./images/favicon.svg'], favicons: [`https://qn.whyour.cn/favicon.svg`],
mfsu: { mfsu: {
strategy: 'eager', strategy: 'eager',
}, },

View File

@ -93,7 +93,11 @@ export default class NotificationService {
}, },
}) })
.json(); .json();
return typeof res.id === 'number'; if (typeof res.id === 'number') {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -109,7 +113,11 @@ export default class NotificationService {
headers: { Authorization: 'Bearer ' + goCqHttpBotToken }, headers: { Authorization: 'Bearer ' + goCqHttpBotToken },
}) })
.json(); .json();
return res.retcode === 0; if (res.retcode === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -128,7 +136,11 @@ export default class NotificationService {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}) })
.json(); .json();
return res.errno === 0 || res.data.errno === 0; if (res.errno === 0 || res.data.errno === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -147,9 +159,14 @@ export default class NotificationService {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}) })
.json(); .json();
return ( if (
res.content.result.length !== undefined && res.content.result.length > 0 res.content.result.length !== undefined &&
); res.content.result.length > 0
) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -166,7 +183,11 @@ export default class NotificationService {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}) })
.json(); .json();
return res.success; if (res.success) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -190,7 +211,11 @@ export default class NotificationService {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}) })
.json(); .json();
return res.code === 200; if (res.code === 200) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -234,7 +259,11 @@ export default class NotificationService {
agent, agent,
}) })
.json(); .json();
return !!res.ok; if (res.ok) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -263,7 +292,11 @@ export default class NotificationService {
}, },
}) })
.json(); .json();
return res.errcode === 0; if (res.errcode === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -284,7 +317,11 @@ export default class NotificationService {
}, },
}) })
.json(); .json();
return res.errcode === 0; if (res.errcode === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -359,7 +396,11 @@ export default class NotificationService {
) )
.json(); .json();
return res.errcode === 0; if (res.errcode === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -403,8 +444,11 @@ export default class NotificationService {
}, },
}) })
.json(); .json();
if (res.code === 0) {
return res.code === 0; return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -422,7 +466,11 @@ export default class NotificationService {
}) })
.json(); .json();
return res.ret === 0; if (res.ret === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -444,7 +492,11 @@ export default class NotificationService {
}) })
.json(); .json();
return res.code === 200; if (res.code === 200) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -468,7 +520,11 @@ export default class NotificationService {
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
}) })
.json(); .json();
return res.StatusCode === 0; if (res.StatusCode === 0) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -495,7 +551,11 @@ export default class NotificationService {
transporter.close(); transporter.close();
return !!info.messageId; if (info.messageId) {
return true;
} else {
throw new Error(JSON.stringify(info));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }
@ -529,7 +589,11 @@ export default class NotificationService {
}; };
try { try {
const res = await got(formatUrl, options); const res = await got(formatUrl, options);
return String(res.statusCode).startsWith('20'); if (String(res.statusCode).startsWith('20')) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) { } catch (error: any) {
throw new Error(error.response ? error.response.body : error); throw new Error(error.response ? error.response.body : error);
} }

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -4,7 +4,7 @@ import config from './config';
import { history } from '@umijs/max'; import { history } from '@umijs/max';
message.config({ message.config({
duration: 1.5, duration: 2,
}); });
const time = Date.now(); const time = Date.now();
@ -23,7 +23,10 @@ const errorHandler = function (error: any) {
history.push('/login'); history.push('/login');
} }
} else { } else {
message.error(msg); message.error({
content: msg,
style: { maxWidth: 500, margin: '0 auto' },
});
} }
} else { } else {
console.log(error.message); console.log(error.message);
@ -66,7 +69,11 @@ _request.interceptors.response.use(async (response) => {
const res = await response.clone().json(); const res = await response.clone().json();
if (res.code !== 200) { if (res.code !== 200) {
const msg = res.message || res.data; const msg = res.message || res.data;
msg && message.error(msg); msg &&
message.error({
content: msg,
style: { maxWidth: 500, margin: '0 auto' },
});
} }
return res; return res;
} }