mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-23 07:09:01 +01:00
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:
parent
8628bdbe89
commit
693f882f5a
@ -401,6 +401,10 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionUid
|
||||
});
|
||||
}
|
||||
|
||||
if (result?.error) {
|
||||
mainWindow.webContents.send('main:display-error', result.error);
|
||||
}
|
||||
}
|
||||
|
||||
// run post-response script
|
||||
|
@ -56,14 +56,27 @@ class VarsRuntime {
|
||||
...bruContext
|
||||
};
|
||||
|
||||
const errors = new Map();
|
||||
_.each(enabledVars, (v) => {
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user