diff --git a/apps/playground-web/lib/api.ts b/apps/playground-web/lib/api.ts index 44a978c..f23fa7a 100644 --- a/apps/playground-web/lib/api.ts +++ b/apps/playground-web/lib/api.ts @@ -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);