Skip to content

Commit

Permalink
fix invalid syntaxes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianMindee committed Mar 11, 2024
1 parent 2904a37 commit 4a3a43d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
12 changes: 6 additions & 6 deletions creates/async.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const defaults = require("./defaults");
module.exports = {
enqueueAndParse: async (z, inputDocument, apiOwner, apiName, apiVersion, headers, maxRetries=60) => {
enqueueAndParse: async (z, inputDocument, apiOwner, apiName, apiVersion, headers, maxRetries = 60) => {
const enqueueResponse = await z.request({
url: `https://api.mindee.net/v1/products/${apiOwner}/${apiName}/v${apiVersion}/predict_async`,
method: 'POST',
Expand All @@ -12,9 +12,9 @@ module.exports = {

const enqueueJson = JSON.parse(enqueueResponse.content);

if (enqueueJson?.api_request?.job?.id) {
const jobId = enqueueJson.api_request.job.id;
let retryCount = 0;
let retryCount = 0;
if (enqueueJson?.job?.id) {
const jobId = enqueueJson.job.id;
let parseQueuedResponse = null;
while (retryCount < maxRetries) {
await new Promise(resolve => setTimeout(resolve, 2000));
Expand All @@ -28,15 +28,15 @@ module.exports = {
retryCount++;
let parseQueuedJson = JSON.parse(parseQueuedResponse.content);

if (parseQueuedJson && parseQueuedJson?.job && parseQueuedJson.job === "completed" || parseQueuedJson.job === "failed") {
if (parseQueuedJson && parseQueuedJson?.job && parseQueuedJson.job?.status === "completed" || parseQueuedJson.job?.status === "failed") {
return parseQueuedResponse;
}
}
}
if (enqueueJson?.api_request?.error && Object.keys(enqueueJson.api_request.error).length > 0) {
throw new Error(JSON.stringify(enqueueJson.api_request.error));
} else {
throw new Error("Could not enqueue file properly.");
throw new Error(`Could not enqueue file properly.`);
}
}
}
4 changes: 2 additions & 2 deletions creates/mindee_generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module.exports = {
.split('/');
const apiOwner = splitUrl[0];
const apiName = splitUrl[1];
const response = enqueueAndParse(z, bundle.inputData.document, apiOwner, apiName, apiVersion, defaults.postHeaders, bundle.inputData.requestSettingsData.max_async_retries);
return promise.then((response) => JSON.parse(response.content));
const response = enqueueAndParse(z, bundle.inputData.document, apiOwner, apiName, apiVersion, defaults.postHeaders, 60);
return response.then((res) => JSON.parse(res.content));
},
sample: {
"api_request": {
Expand Down
3 changes: 0 additions & 3 deletions test/mindee.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const bundle = {
oauth_token: process.env.OAUTH_TOKEN,
oauth_token_secret: process.env.OAUTH_TOKEN_SECRET,
},
requestSettingsData: {
max_async_retries: 60,
},
inputData: {},
};
zapier.tools.env.inject();
Expand Down

0 comments on commit 4a3a43d

Please sign in to comment.