catch post request variable evaluation errors (#2324)

fix #2005

- display post request variable evaluation errors in a toast, each individual variable error on a new line
- display the response body (was previously replaced by the an error "Error invoking remote method 'send-http-request': ..."
This commit is contained in:
Raphaël Bideau 2024-06-14 13:38:57 +02:00 committed by GitHub
parent 8628bdbe89
commit 693f882f5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -401,6 +401,10 @@ const registerNetworkIpc = (mainWindow) => {
collectionUid
});
}
if (result?.error) {
mainWindow.webContents.send('main:display-error', result.error);
}
}
// run post-response script

View File

@ -56,14 +56,27 @@ class VarsRuntime {
...bruContext
};
const errors = new Map();
_.each(enabledVars, (v) => {
const value = evaluateJsExpression(v.value, context);
bru.setVar(v.name, value);
try {
const value = evaluateJsExpression(v.value, context);
bru.setVar(v.name, value);
} catch (error) {
errors.set(v.name, error);
}
});
let error = null;
if (errors.size > 0) {
// Format all errors as a single string to be displayed in a toast
const errorMessage = [...errors.entries()].map(([name, err]) => `${name}: ${err.message ?? err}`).join('\n');
error = `${errors.size} error${errors.size === 1 ? '' : 's'} in post response variables: \n${errorMessage}`;
}
return {
envVariables,
collectionVariables
collectionVariables,
error
};
}
}