Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Handled error handling to pre-request script execution
Andrew Bastinb1d3fa3f42ff
diff --git a/helpers/preRequest.js b/helpers/preRequest.jsindex dc5ba9a96..6375fece0 100644--- a/helpers/preRequest.js+++ b/helpers/preRequest.js@@ -1,20 +1,22 @@export default function getEnvironmentVariablesFromScript(script) {let _variables = {}- // the pw object is the proxy by which pre-request scripts can pass variables to the request.- // for security and control purposes, this is the only way a pre-request script should modify variables.- let pw = {- environment: {- set: (key, value) => (_variables[key] = value),- },- env: {- set: (key, value) => (_variables[key] = value),- },- // globals that the script is allowed to have access to.- }+ try {+ // the pw object is the proxy by which pre-request scripts can pass variables to the request.+ // for security and control purposes, this is the only way a pre-request script should modify variables.+ let pw = {+ environment: {+ set: (key, value) => (_variables[key] = value),+ },+ env: {+ set: (key, value) => (_variables[key] = value),+ },+ // globals that the script is allowed to have access to.+ }- // run pre-request script within this function so that it has access to the pw object.- new Function("pw", script)(pw)+ // run pre-request script within this function so that it has access to the pw object.+ new Function("pw", script)(pw)+ } catch (_e) {}return _variables}