Skip to content

Commit

Permalink
Fix an issue where the payload would not be set correctly in subseque…
Browse files Browse the repository at this point in the history
…nt runs
  • Loading branch information
danmindru committed Aug 27, 2022
1 parent 6196490 commit f966ba6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/results/useResultRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const useResultRunner = ({
headerNodeScriptData?.text
);

if (!isSuccess) {
if (!isSuccess || !result) {
throw new Error('Node script failed.');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export const HeaderNodeMode = () => {

if (electronAPI) {
const { result } = await electronAPI.runNodeCmd(cmd);
setLastNodeOutput(result);

if (!result) {
setLastNodeOutput(
'Script run produced no output. Remember to return a value at the end of the script.'
);
} else {
setLastNodeOutput(result);
}
}
};

Expand Down
24 changes: 8 additions & 16 deletions packages/ui/src/state/useSearchState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,13 @@ export const useSearchState = ({ initialState }: { [key: string]: any }) => {
};

const setSettings = (item: ClobbrUIResultListItem) => {
const getPayloadJson = (data: { [key: string]: any }) => {
try {
return {
json: data,
text: JSON.stringify(initialState.search.data, null, 2),
valid: true
};
} catch {
return {
json: {},
text: '{}',
valid: true
};
}
};
const payloadData = item.data
? {
json: item.data,
text: JSON.stringify(item.data, null, 2),
valid: true // TODO validate again?
}
: null;

setUrl({
displayText: item.url.replace(/^https?:\/\//, ''),
Expand All @@ -205,7 +197,7 @@ export const useSearchState = ({ initialState }: { [key: string]: any }) => {
setSsl(item.ssl);
setIterations(item.iterations);
setVerb(item.verb);
setPayloadData(getPayloadJson(item.data));
setPayloadData(payloadData);
setHeaderInputMode(item.headerInputMode);
setHeaderItems(item.headers);
setHeaderShellCmd(item.headerShellCmd);
Expand Down

0 comments on commit f966ba6

Please sign in to comment.