Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Aasif Khan authored and Aasif Khan committed Nov 27, 2024
1 parent 3e5a24c commit 28d1330
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions apps/playground-web/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,16 @@ export const executeShellCommandOnServer = async (

try {
const response = await WebService.post(cmdExecURL, cmdOptions);

// Type guard to check if the body is MonoResponse
if ('data' in response.body) {
const parsedResponse = response.body as MonoResponse;
return {headers: response.headers, body: parsedResponse}; // MonoResponse
const body = response?.body as MonoResponse | undefined;
if (body?.data || body?.error) {
return { headers: response.headers, body };
}
throw new Error('Unexpected response structure');
} else {
throw new Error('Unexpected response structure');
}


// // Check if the response contains data or if it's an error response
// if (response?.body?.data) {
// return response;
// } else if (response?.body?.error) {
// return response;
// } else {
// throw new Error('Unexpected response structure');
// }
} catch (error) {
// Propagate the error from the backend exactly as it is
console.error('Error executing command:', error);
Expand Down

0 comments on commit 28d1330

Please sign in to comment.