Merge pull request #587 from rayoz12/552-run-post-response-vars-and-scripts-on-error

Fixes: #552: Runs Post response vars and scripts on HTTP error.
This commit is contained in:
Anoop M D 2023-10-18 11:15:49 +05:30 committed by GitHub
commit 5f77ee342b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -461,6 +461,56 @@ const registerNetworkIpc = (mainWindow) => {
});
}
// run post-response vars
const postResponseVars = get(request, 'vars.res', []);
if (postResponseVars && postResponseVars.length) {
const varsRuntime = new VarsRuntime();
const result = varsRuntime.runPostResponseVars(
postResponseVars,
request,
error.response,
envVars,
collectionVariables,
collectionPath,
processEnvVars
);
if (result) {
mainWindow.webContents.send('main:script-environment-update', {
envVariables: result.envVariables,
collectionVariables: result.collectionVariables,
requestUid,
collectionUid
});
}
}
// run post-response script
const responseScript = compact([get(collectionRoot, 'request.script.res'), get(request, 'script.res')]).join(
os.EOL
);
if (responseScript && responseScript.length) {
const scriptRuntime = new ScriptRuntime();
const result = await scriptRuntime.runResponseScript(
decomment(responseScript),
request,
error.response,
envVars,
collectionVariables,
collectionPath,
onConsoleLog,
processEnvVars,
scriptingConfig
);
mainWindow.webContents.send('main:script-environment-update', {
envVariables: result.envVariables,
collectionVariables: result.collectionVariables,
requestUid,
collectionUid
});
}
// run tests
const testFile = compact([
get(collectionRoot, 'request.tests'),