Skip to content

Commit

Permalink
fix: not auto remove worker if can't call api
Browse files Browse the repository at this point in the history
  • Loading branch information
woody146 committed Nov 6, 2023
1 parent 4f9bda2 commit 84923d8
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { WorkerService } from '../services/worker.js';
import { getEntityManager } from './datasource.js';

function generatePath(urlPattern: string, params: Record<string, any>) {
const retParams = { ...params };
const parts = urlPattern.split('/');
Expand Down Expand Up @@ -44,19 +41,12 @@ export function fetchApi({
headers: { 'Content-Type': 'application/json' },
method,
body,
})
.then(async (resp) => {
if (resp.status > 400) {
const message = await resp.text();
throw { code: resp.status, message };
} else {
return resp.json();
}
})
.catch((e) => {
if (port) {
new WorkerService(getEntityManager()).updateError(host, port);
}
throw e;
});
}).then(async (resp) => {
if (resp.status > 400) {
const message = await resp.text();
throw { code: resp.status, message };
} else {
return resp.json();
}
});
}

0 comments on commit 84923d8

Please sign in to comment.