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) {
this.app.error = error?.response?.data?.error;
throw error;
return;
} else if (this.app.error) {
this.app.error = null;

View File

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

View File

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

View File

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