1

I am using ArcGIS JavaScript API 4.21 (with TypeScript). @arcgis/core/tasks/Geoprocessor is deprecated since version 4.20. So I am using @arcgis/core/rest/geoprocessor instead.

import JobInfo from "@arcgis/core/rest/support/JobInfo";
import ParameterValue from "@arcgis/core/rest/support/ParameterValue";

import * as geoprocessor from "@arcgis/core/rest/geoprocessor";

const GEO_PROCESSING_URL = "..."

// ...

async function execute(): Promise<void> {

  const params: { /* ... */ }

  const jobInfo: JobInfo = await geoprocessor.submitJob(
    GEO_PROCESSING_URL,
    params,
  );

  await jobInfo.waitForJobCompletion({
    statusCallback: checkJobStatus,
  });

  const result: ParameterValue = await jobInfo.fetchResultData("output_file");

  console.log(result.value.toJSON().url);

}

function checkJobStatus(jobInfo: JobInfo): void {
  console.log(jobInfo);
}

Above code works well as long as there is no error. If an error occurs, I get following error message (URL obfuscated) in the developer console:

ERROR Error: Uncaught (in promise): p: {"sourceUrl":"https://..."}

How can I handle failed geoprocessing tasks?

1 Answer 1

2

Use try/catch if you are using async/awaits.

I think that @arcgis/core/rest/geoprocessor could use some (more) examples. Hope that this helps someone else.

import JobInfo from "@arcgis/core/rest/support/JobInfo";
import ParameterValue from "@arcgis/core/rest/support/ParameterValue";

import GPMessage from "@arcgis/core/rest/support/GPMessage";

// ...

async function execute(): Promise<void> {

  // ...

  try {

    await jobInfo.waitForJobCompletion({
      statusCallback: checkJobStatus,
    });

    const result: ParameterValue = await jobInfo.fetchResultData("output_file");
  
    console.log(result.value.toJSON().url)

  }
  catch(error) {

    (<JobInfo>error).messages.forEach((message: GPMessage) => {
      console.log(message.toJSON())
    })

  }

}

// ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.