Skip to content

Commit

Permalink
Merge pull request #16 from markusguenther/bugfix/prevent-json-error
Browse files Browse the repository at this point in the history
BUGFIX: Prevent json parse error
  • Loading branch information
Sebobo committed Jan 10, 2024
2 parents 187fb5c + ab9f7c5 commit 38712c4
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Resources/Private/JavaScript/Terminal/src/helpers/fetchCommands.ts
Expand Up @@ -14,12 +14,34 @@ const fetchCommands = async (endPoint: string): Promise<{ success: boolean; resu
'Content-Type': 'application/json',
},
}))
.then((response: Response) => response && response.json())
.then((response: Response) => {
if (!response.ok) {
return {
success: false,
result: {},
};
}

return (
response &&
response
.json()
.then((data: CommandList) => {
return data;
})
.catch((error: Error) => {
return {
success: false,
result: {},
};
})
);
})
.catch((error: Error) => {
logToConsole('error', error.message);
return {
success: false,
result: [],
result: {},
};
});
};
Expand Down

0 comments on commit 38712c4

Please sign in to comment.