diff --git a/lib/job.js b/lib/job.js index 443ab4b..40153ef 100644 --- a/lib/job.js +++ b/lib/job.js @@ -60,6 +60,26 @@ function run(instance, job_id, request_doc, asJson) { // in case of errors var result = { error : util.format('Starting job "%s" on %s failed', job_id, instance), fault : res.body.fault }; + + // handle case of import job with res.body.fault.type === 'UnknownPropertyException' + // this must be a support user, so we need to re-run with normal job parameters form + if (job_id === 'sfcc-site-archive-import' && request_doc.file_name + && res.body.fault && res.body.fault.type === 'UnknownPropertyException') { + if (!asJson) { + console.warn("internal users must use different form for import; re-running job", request_doc) + } + + return run(instance, job_id, { + parameters: [ + { + name: "ImportFile", + value: request_doc.file_name + } + ] + }, asJson); + } + // TODO handle export as well + if (asJson) { console.json(result); } else { @@ -160,6 +180,25 @@ function runSync(instance, job_id, request_doc, asJson, failFast) { // in case of errors var result = { error : util.format('Starting job "%s" on %s failed', job_id, instance), fault : res.body.fault }; + + // handle case of import job with res.body.fault.type === 'UnknownPropertyException' + // this must be a support user, so we need to re-run with normal job parameters form + if (job_id === 'sfcc-site-archive-import' && request_doc.file_name + && res.body.fault && res.body.fault.type === 'UnknownPropertyException') { + if (!asJson) { + console.warn("internal users must use different form for import; re-running job", request_doc) + } + + return runSync(instance, job_id, { + parameters: [ + { + name: "ImportFile", + value: request_doc.file_name + } + ] + }, asJson); + } + if (asJson) { console.json(result); } else { @@ -362,4 +401,4 @@ module.exports.api = { }); }); } -}; \ No newline at end of file +};