I need to make two server-side async context.request calls.
When I place each call in it’s own Action everything works as expected.
But when I combine both calls into one server-side Action it throws an Unexpected server error.
So why does bubble throw a server error when using two async context.request calls in the same action?
Here is working example where I call https://www.google.com and use the statusCode it returns. I’m returning the statusCode as a simple example, I don’t actually care what code it returns.
EXAMPLE 1: Two actions. Each action has it’s own server-side async “context.request” call. This works as expected.
The workflow:
Step 1 Action Code (“Test - Make First Call”):
function(properties, context) {
//The first call using context.request
const first_call = () => {
let response = context.request("https://www.google.com");
return response.statusCode;
};
//Do async calls and return the data
return context.async( async callback => {
try {
let first_call_status = await first_call(); //Do this first and wait for a response
let bubble_return_object = {
first_call_status: first_call_status, //Outputs something from the first await
};
callback( undefined, bubble_return_object );
}
catch {
callback (error);
}
});
}
Step 2 Action Code (“Test - Add Second Call”):
function(properties, context) {
const first_call_status = properties.first_call_status;
//The second call using context.request
const add_second_call = (first_call_status) => {
let response = context.request("https://www.google.com");
let combined_status = first_call_status + response.statusCode;
return combined_status;
};
//Do async calls and return the data
return context.async( async callback => {
try {
let combined_status = await add_second_call(first_call_status); //Then do this using the response
let bubble_return_object = {
combined_status: combined_status, //Outputs something from the second await
};
callback( undefined, bubble_return_object );
}
catch {
callback (error);
}
});
}
EXAMPLE 2: Two server-side async context.requests combined and placed inside one single action. This does NOT work. It throws an “Unexpected server error”.
The workflow:
Step 1 Action Code ("Test - Make First Call AND Add Second Call):
function(properties, context) {
//The first call using context.request
const first_call = () => {
let response = context.request("https://www.google.com");
return response.statusCode;
};
//The second call using context.request
const add_second_call = (first_call_status) => {
let response = context.request("https://www.google.com");
let combined_status = first_call_status + response.statusCode;
return combined_status;
};
//Do async calls and return the data
return context.async( async callback => {
try {
let first_call_status = await first_call(); //Do this first and wait for a response
let combined_status = await add_second_call(first_call_status); //Then do this using the response
let bubble_return_object = {
first_call_status: first_call_status, //Outputs something from the first await
combined_status: combined_status, //Outputs something from the second await
};
callback( undefined, bubble_return_object );
}
catch {
callback (error);
}
});
}
Here is the console.log error:
And here is the server log error:
So why does it throw a server error when using two async context.request calls in the same action?



