Catch xlsx error (#1487)

* catch potential xlsx errors

* clear worksheet errors when starting new connections
This commit is contained in:
Alex Christoffer Rasmussen
2025-02-12 13:38:18 +01:00
committed by GitHub
parent bac11adeb1
commit 0b36608134
2 changed files with 12 additions and 0 deletions
@@ -76,6 +76,7 @@ export default function GSheetSetup(props: GSheetSetupProps) {
const handleConnect = async () => {
if (!file) return;
if (!sheetId) return;
patchStepData({ worksheet: { available: false, error: '' } });
setLoading('connect');
const result = await connect(file, sheetId);
@@ -208,6 +208,17 @@ async function verifySheet(
});
return { worksheetOptions: spreadsheets.data.sheets.map((i) => i.properties.title) };
} catch (error) {
// attempt to catch errors caused by importing xlsx
if (
error.code === 400 &&
Array.isArray(error.errors) &&
error.errors[0].reason === 'failedPrecondition' &&
error.errors[0].message === 'This operation is not supported for this document'
) {
throw new Error(
'This operation is not supported for this document. the reason is most likely that this is a .xlsx document',
);
}
const errorMessage = getErrorMessage(error);
throw new Error(`Failed to verify sheet: ${errorMessage}`);
}