Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Catch post request variable evaluation errors #2324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ const registerNetworkIpc = (mainWindow) => {
collectionUid
});
}

if (result?.error) {
mainWindow.webContents.send('main:display-error', result.error);
}
}

// run post-response script
Expand Down
19 changes: 16 additions & 3 deletions packages/bruno-js/src/runtime/vars-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
Expand Down