Skip to content

Commit

Permalink
refactor: improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
bgatellier committed Apr 13, 2024
1 parent c42822e commit 800bd00
Showing 1 changed file with 20 additions and 37 deletions.
57 changes: 20 additions & 37 deletions assets/js/services/AnalysisService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,25 @@ class AnalysisService {
try {
EcoIndexDialog.openPendingAnalysis(url);

ApiService.newAnalysisTaskByURL(url).then(
(taskId) => {
ApiService.fetchAnalysisTaskById(taskId).then(
(taskResult) => {
const ecoindex = taskResult.ecoindex_result;
const taskId = await ApiService.newAnalysisTaskByURL(url)

if (taskResult.status === "SUCCESS" && ecoindex.status === "SUCCESS") {
ResultCacheService.add(ecoindex.detail);
redirectToResults(taskId, resultUrlPrefix);
}
const taskResult = await ApiService.fetchAnalysisTaskById(taskId)

const ecoindex = taskResult.ecoindex_result;

if (taskResult.status === "SUCCESS" && ecoindex.status === "FAILURE") {
const e = taskResult.ecoindex_result.error;
EcoIndexDialog.openErrorMessage(e.status_code, e);
}
if (taskResult.status === "SUCCESS" && ecoindex.status === "SUCCESS") {
ResultCacheService.add(ecoindex.detail);
redirectToResults(taskId, resultUrlPrefix);
}

if (taskResult.status === "FAILURE") {
EcoIndexDialog.openErrorMessage(599, taskResult.task_error);
}
},
(e) => {
this.#handleError(e);
}
);
},
(e) => {
this.#handleError(e);
}
);
if (taskResult.status === "SUCCESS" && ecoindex.status === "FAILURE") {
const e = taskResult.ecoindex_result.error;
EcoIndexDialog.openErrorMessage(e.status_code, e);
}

if (taskResult.status === "FAILURE") {
EcoIndexDialog.openErrorMessage(599, taskResult.task_error);
}
} catch (e) {
this.#handleError(e);
}
Expand Down Expand Up @@ -79,17 +69,10 @@ class AnalysisService {
// Otherwise fetch from api
try {
EcoIndexDialog.openAnalysisRetrieval();
await ApiService.fetchAnalysisById(id).then(
(result) => {
apiResult = result;
ResultCacheService.add(result);
redirectToResults(result.id, resultPagePrefix);
EcoIndexDialog.close();
},
(e) => {
this.#handleError(e);
}
);
apiResult = await ApiService.fetchAnalysisById(id)
ResultCacheService.add(result);
redirectToResults(result.id, resultPagePrefix);
EcoIndexDialog.close();
} catch (e) {
this.#handleError(e);
return null;
Expand Down

0 comments on commit 800bd00

Please sign in to comment.