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?

asked Nov 29, 2021 at 20:13

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())
 })
 }
}
// ...
answered Nov 29, 2021 at 20:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.