fix: window reload after pm load failed (#2605)

This commit is contained in:
chenos 2023-09-06 22:43:43 +08:00 committed by GitHub
parent 2484c8ffb2
commit 3461c29411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -64,6 +64,7 @@ export class APIClient extends APIClientSDK {
} }
if (this.app.maintaining) { if (this.app.maintaining) {
this.app.error = error?.response?.data?.error; this.app.error = error?.response?.data?.error;
throw error;
return; return;
} else if (this.app.error) { } else if (this.app.error) {
this.app.error = null; this.app.error = null;

View File

@ -126,6 +126,7 @@ export class Application {
} }
async load() { async load() {
let loadFailed = false;
this.ws.on('message', (event) => { this.ws.on('message', (event) => {
const data = JSON.parse(event.data); const data = JSON.parse(event.data);
console.log(data.payload); console.log(data.payload);
@ -142,6 +143,10 @@ export class Application {
this.maintaining = true; this.maintaining = true;
this.error = data.payload; this.error = data.payload;
} else { } else {
console.log('loadFailed', loadFailed);
if (loadFailed) {
window.location.reload();
}
this.maintaining = false; this.maintaining = false;
this.maintained = true; this.maintained = true;
this.error = null; this.error = null;
@ -155,6 +160,7 @@ export class Application {
this.loading = true; this.loading = true;
await this.pm.load(); await this.pm.load();
} catch (error) { } catch (error) {
loadFailed = true;
this.error = { this.error = {
code: 'LOAD_ERROR', code: 'LOAD_ERROR',
message: error.message, message: error.message,

View File

@ -5,9 +5,6 @@ export function useAppPluginLoad(app: Application) {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<Error | null>(null); const [error, setError] = useState<Error | null>(null);
useEffect(() => { useEffect(() => {
app.ws.on('message', (event) => {
console.log(event.data);
});
async function run() { async function run() {
try { try {
await app.load(); await app.load();

View File

@ -141,6 +141,8 @@ const getProps = (app: Application) => {
}; };
return { ...props, ...commands[app.error?.command?.name] }; return { ...props, ...commands[app.error?.command?.name] };
} }
return {};
}; };
const AppMaintaining: FC<{ app: Application; error: Error }> = observer(({ app }) => { const AppMaintaining: FC<{ app: Application; error: Error }> = observer(({ app }) => {