Skip to content

Commit

Permalink
catch post request variable evaluation errors
Browse files Browse the repository at this point in the history
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': ..."
  • Loading branch information
rbideau committed May 22, 2024
1 parent d24c0ba commit 35e75d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 35e75d2

Please sign in to comment.