From d40ec715b2601b94aa67479c02aec9553881dd3d Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 18 Sep 2024 22:31:48 +0530 Subject: [PATCH] feat: return promise --- src/api/interpretation.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/api/interpretation.ts b/src/api/interpretation.ts index 7cfd2561..3081caf2 100644 --- a/src/api/interpretation.ts +++ b/src/api/interpretation.ts @@ -1,12 +1,18 @@ import { default as axios } from "axios"; // todo: proper typescript types for params -export const handleUploadCredentials = async (fileName: any, credentials: any, spreadsheetId: any, range: any) => { +export const handleUploadCredentials = async (fileName: any, credentials: any, spreadsheetId: any, range: any): Promise => { try { - await axios.post('http://localhost:8080/integration/upload-credentials', { fileName, credentials: JSON.parse(credentials), spreadsheetId, range }); - alert('Service Account credentials saved successfully.'); + const response = await axios.post('http://localhost:8080/integration/upload-credentials', { fileName, credentials: JSON.parse(credentials), spreadsheetId, range }); + if (response.status === 200) { + alert('Service Account credentials saved successfully.'); + return response.data; + } else { + throw new Error(`Couldn't make gsheet integration for ${fileName}`); + } } catch (error) { console.error('Error uploading credentials:', error); alert('Failed to upload credentials.'); + return false; } }; \ No newline at end of file