From 826f214f0f1d166f753d65c0519b643544a0c24a Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 24 May 2023 23:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E9=94=99=E8=AF=AF=E6=97=B6=E6=8F=90=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E6=B8=85=E6=99=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .umirc.ts | 2 +- back/services/notify.ts | 102 +++++++++++++++++++++++++++++++------- public/images/favicon.svg | 1 - src/utils/http.ts | 13 +++-- 4 files changed, 94 insertions(+), 24 deletions(-) delete mode 100644 public/images/favicon.svg diff --git a/.umirc.ts b/.umirc.ts index cfee0224..b01c4b94 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -7,7 +7,7 @@ export default defineConfig({ antd: {}, outputPath: 'static/dist', fastRefresh: true, - favicons: ['./images/favicon.svg'], + favicons: [`https://qn.whyour.cn/favicon.svg`], mfsu: { strategy: 'eager', }, diff --git a/back/services/notify.ts b/back/services/notify.ts index 33ff770e..3983b6cb 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -93,7 +93,11 @@ export default class NotificationService { }, }) .json(); - return typeof res.id === 'number'; + if (typeof res.id === 'number') { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -109,7 +113,11 @@ export default class NotificationService { headers: { Authorization: 'Bearer ' + goCqHttpBotToken }, }) .json(); - return res.retcode === 0; + if (res.retcode === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { 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' }, }) .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) { 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' }, }) .json(); - return ( - res.content.result.length !== undefined && res.content.result.length > 0 - ); + if ( + res.content.result.length !== undefined && + res.content.result.length > 0 + ) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { 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' }, }) .json(); - return res.success; + if (res.success) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { 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' }, }) .json(); - return res.code === 200; + if (res.code === 200) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -234,7 +259,11 @@ export default class NotificationService { agent, }) .json(); - return !!res.ok; + if (res.ok) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -263,7 +292,11 @@ export default class NotificationService { }, }) .json(); - return res.errcode === 0; + if (res.errcode === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -284,7 +317,11 @@ export default class NotificationService { }, }) .json(); - return res.errcode === 0; + if (res.errcode === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -359,7 +396,11 @@ export default class NotificationService { ) .json(); - return res.errcode === 0; + if (res.errcode === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -403,8 +444,11 @@ export default class NotificationService { }, }) .json(); - - return res.code === 0; + if (res.code === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -422,7 +466,11 @@ export default class NotificationService { }) .json(); - return res.ret === 0; + if (res.ret === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -444,7 +492,11 @@ export default class NotificationService { }) .json(); - return res.code === 200; + if (res.code === 200) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -468,7 +520,11 @@ export default class NotificationService { headers: { 'Content-Type': 'application/json' }, }) .json(); - return res.StatusCode === 0; + if (res.StatusCode === 0) { + return true; + } else { + throw new Error(JSON.stringify(res)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -495,7 +551,11 @@ export default class NotificationService { transporter.close(); - return !!info.messageId; + if (info.messageId) { + return true; + } else { + throw new Error(JSON.stringify(info)); + } } catch (error: any) { throw new Error(error.response ? error.response.body : error); } @@ -529,7 +589,11 @@ export default class NotificationService { }; try { 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) { throw new Error(error.response ? error.response.body : error); } diff --git a/public/images/favicon.svg b/public/images/favicon.svg deleted file mode 100644 index 383291b0..00000000 --- a/public/images/favicon.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/utils/http.ts b/src/utils/http.ts index aa14169c..20991189 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -4,7 +4,7 @@ import config from './config'; import { history } from '@umijs/max'; message.config({ - duration: 1.5, + duration: 2, }); const time = Date.now(); @@ -23,7 +23,10 @@ const errorHandler = function (error: any) { history.push('/login'); } } else { - message.error(msg); + message.error({ + content: msg, + style: { maxWidth: 500, margin: '0 auto' }, + }); } } else { console.log(error.message); @@ -66,7 +69,11 @@ _request.interceptors.response.use(async (response) => { const res = await response.clone().json(); if (res.code !== 200) { const msg = res.message || res.data; - msg && message.error(msg); + msg && + message.error({ + content: msg, + style: { maxWidth: 500, margin: '0 auto' }, + }); } return res; }