Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Jan 16, 2025
1 parent 471ffd9 commit ffaa5ba
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1357,11 +1357,10 @@ qx.Class.define("osparc.data.Resources", {
res[endpoint](params.url || null, params.data || null);
}

res.addListenerOnce(endpoint + "Success", e => {
const successCB = e => {
const response = e.getRequest().getResponse();
const endpointDef = resourceDefinition.endpoints[endpoint];
const data = endpointDef.isJsonFile ? response : response.data;
const useCache = ("useCache" in endpointDef) ? endpointDef.useCache : resourceDefinition.useCache;
// OM: Temporary solution until the quality object is better defined
if (data && endpoint.includes("get") && ["studies", "templates"].includes(resource)) {
if (Array.isArray(data)) {
Expand All @@ -1372,6 +1371,8 @@ qx.Class.define("osparc.data.Resources", {
osparc.metadata.Quality.attachQualityToObject(data);
}
}

const useCache = ("useCache" in endpointDef) ? endpointDef.useCache : resourceDefinition.useCache;
if (useCache) {
if (endpoint.includes("delete") && resourceDefinition["deleteId"] && resourceDefinition["deleteId"] in params.url) {
const deleteId = params.url[resourceDefinition["deleteId"]];
Expand All @@ -1386,16 +1387,18 @@ qx.Class.define("osparc.data.Resources", {
}
}
}

res.dispose();

if ("resolveWResponse" in options && options.resolveWResponse) {
response.params = params;
resolve(response);
} else {
resolve(data);
}
}, this);
};

res.addListener(endpoint + "Error", e => {
const errorCB = e => {
if (e.getPhase() === "timeout") {
if (options.timeout && options.timeoutRetries) {
options.timeoutRetries--;
Expand Down Expand Up @@ -1449,8 +1452,12 @@ qx.Class.define("osparc.data.Resources", {
err.status = status;
}
reject(err);
});
};

const successEndpoint = endpoint + "Success";
const errorEndpoint = endpoint + "Error";
res.addListenerOnce(successEndpoint, e => successCB(e), this);
res.addListener(errorEndpoint, e => errorCB(e), this);
sendRequest();
});
},
Expand Down

0 comments on commit ffaa5ba

Please sign in to comment.