mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修改服务异常判断逻辑
This commit is contained in:
parent
66df445bd5
commit
7edd91f923
|
@ -6,15 +6,12 @@ import config from './config';
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.get('/api/public/panel/log', (req, res) => {
|
app.get('/api/public/panel/log', (req, res) => {
|
||||||
exec(
|
exec('tail -n 300 ~/.pm2/logs/panel-error.log', (err, stdout, stderr) => {
|
||||||
'pm2 logs panel --lines 500 --nostream --timestamp',
|
if (err || stderr) {
|
||||||
(err, stdout, stderr) => {
|
return res.send({ code: 400, message: (err && err.message) || stderr });
|
||||||
if (err || stderr) {
|
}
|
||||||
return res.send({ code: 400, message: (err && err.message) || stderr });
|
return res.send({ code: 200, data: stdout });
|
||||||
}
|
});
|
||||||
return res.send({ code: 200, data: stdout });
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app
|
app
|
||||||
|
|
5246
pnpm-lock.yaml
5246
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -9,20 +9,37 @@ import './index.less';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
|
||||||
const Error = () => {
|
const Error = () => {
|
||||||
const { user, theme } = useOutletContext<SharedContext>();
|
const { user, theme, reloadUser } = useOutletContext<SharedContext>();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [data, setData] = useState('暂无日志');
|
const [data, setData] = useState('暂无日志');
|
||||||
|
|
||||||
const getLog = () => {
|
const getTimes = () => {
|
||||||
setLoading(true);
|
return parseInt(localStorage.getItem('error_retry_times') || '0', 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
let times = getTimes();
|
||||||
|
|
||||||
|
const getLog = (needLoading: boolean = true) => {
|
||||||
|
needLoading && setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}public/panel/log`)
|
.get(`${config.apiPrefix}public/panel/log`)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
setData(data);
|
setData(data);
|
||||||
|
if (!data) {
|
||||||
|
times = getTimes();
|
||||||
|
if (times > 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem('error_retry_times', `${times + 1}`);
|
||||||
|
setTimeout(() => {
|
||||||
|
reloadUser();
|
||||||
|
getLog(false);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => needLoading && setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -39,7 +56,7 @@ const Error = () => {
|
||||||
<div className="error-wrapper">
|
<div className="error-wrapper">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<PageLoading />
|
<PageLoading />
|
||||||
) : (
|
) : data ? (
|
||||||
<Terminal
|
<Terminal
|
||||||
name="服务错误"
|
name="服务错误"
|
||||||
colorMode={theme === 'vs-dark' ? ColorMode.Dark : ColorMode.Light}
|
colorMode={theme === 'vs-dark' ? ColorMode.Dark : ColorMode.Light}
|
||||||
|
@ -55,6 +72,10 @@ const Error = () => {
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
) : times > 5 ? (
|
||||||
|
<>服务启动超时,请手动进入容器执行 ql -l check 后刷新再试</>
|
||||||
|
) : (
|
||||||
|
<PageLoading tip="启动中,请稍后..." />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -56,7 +56,6 @@ _request.interceptors.request.use((url, options) => {
|
||||||
_request.interceptors.response.use(async (response) => {
|
_request.interceptors.response.use(async (response) => {
|
||||||
const responseStatus = response.status;
|
const responseStatus = response.status;
|
||||||
if ([502, 504].includes(responseStatus)) {
|
if ([502, 504].includes(responseStatus)) {
|
||||||
message.error('服务异常,请稍后刷新!');
|
|
||||||
history.push('/error');
|
history.push('/error');
|
||||||
} else if (responseStatus === 401) {
|
} else if (responseStatus === 401) {
|
||||||
if (history.location.pathname !== '/login') {
|
if (history.location.pathname !== '/login') {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user