Browse Source

Merge pull request #4705 from nocodb/fix/3927-at-error

fix: proper error if provided url is not shared base
pull/4741/head
Raju Udava 2 years ago committed by GitHub
parent
commit
c853372d1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/nc-gui/components/dlg/AirtableImport.vue
  2. 2
      packages/nc-gui/pages/[projectType]/[projectId]/index/index.vue
  3. 39
      packages/nocodb/src/lib/meta/api/sync/helpers/fetchAT.ts
  4. 7
      packages/nocodb/src/lib/meta/api/sync/helpers/job.ts
  5. 19
      packages/nocodb/src/lib/meta/api/sync/importApis.ts

6
packages/nc-gui/components/dlg/AirtableImport.vue

@ -45,8 +45,6 @@ const enableAbort = ref(false)
let socket: Socket | null let socket: Socket | null
let socketInterval: NodeJS.Timer
const syncSource = ref({ const syncSource = ref({
id: '', id: '',
type: 'Airtable', type: 'Airtable',
@ -275,10 +273,10 @@ onMounted(async () => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
if (socket) { if (socket) {
socket.removeAllListeners() socket.off('disconnect')
socket.disconnect() socket.disconnect()
socket.removeAllListeners()
} }
clearInterval(socketInterval)
}) })
</script> </script>

2
packages/nc-gui/pages/[projectType]/[projectId]/index/index.vue

@ -75,7 +75,7 @@ function onEdit(targetKey: number, action: 'add' | 'remove' | string) {
<span class="flex-1" /> <span class="flex-1" />
<div class="flex justify-center self-center mr-2 min-w-[115px]"> <div class="flex justify-center self-center mr-2 min-w-[115px]">
<div v-show="isLoading" class="flex items-center gap-2 ml-3 text-gray-200" data-testid="nc-loading"> <div v-if="isLoading" class="flex items-center gap-2 ml-3 text-gray-200" data-testid="nc-loading">
{{ $t('general.loading') }} {{ $t('general.loading') }}
<MdiLoading class="animate-infinite animate-spin" /> <MdiLoading class="animate-infinite animate-spin" />

39
packages/nocodb/src/lib/meta/api/sync/helpers/fetchAT.ts

@ -36,6 +36,12 @@ async function initialize(shareId) {
info.cookie += ck.split(';')[0] + '; '; info.cookie += ck.split(';')[0] + '; ';
} }
return response.data; return response.data;
})
.catch(() => {
throw {
message:
'Invalid Shared Base ID :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
};
}); });
info.headers = JSON.parse( info.headers = JSON.parse(
@ -64,6 +70,14 @@ async function initialize(shareId) {
} catch (e) { } catch (e) {
console.log(e); console.log(e);
info.initialized = false; info.initialized = false;
if (e.message) {
throw e;
} else {
throw {
message:
'Error processing Shared Base :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
};
}
} }
} }
@ -94,7 +108,10 @@ async function read() {
return response.data; return response.data;
}) })
.catch(() => { .catch(() => {
throw 'Error while fetching'; throw {
message:
'Error Reading :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
};
}); });
return { return {
@ -103,7 +120,10 @@ async function read() {
baseInfo: info.baseInfo, baseInfo: info.baseInfo,
}; };
} else { } else {
throw 'Please initialize first!'; throw {
message:
'Error Initializing :: please try again !!',
};
} }
} }
@ -149,11 +169,17 @@ async function readView(viewId) {
return response.data; return response.data;
}) })
.catch(() => { .catch(() => {
throw 'Error while fetching'; throw {
message:
'Error Reading View :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
};
}); });
return { view: resreq.data }; return { view: resreq.data };
} else { } else {
throw 'Please initialize first!'; throw {
message:
'Error Initializing :: please try again !!',
};
} }
} }
@ -192,7 +218,10 @@ async function readTemplate(templateId) {
return response.data; return response.data;
}) })
.catch(() => { .catch(() => {
throw 'Error while fetching'; throw {
message:
'Error Fetching :: Ensure www.airtable.com/templates/featured/<TemplateID> is accessible.',
};
}); });
return { template: resreq }; return { template: resreq };
} }

7
packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

@ -191,6 +191,13 @@ export default async (
rtc.fetchAt.count++; rtc.fetchAt.count++;
rtc.fetchAt.time += duration; rtc.fetchAt.time += duration;
if (!ft.baseId) {
throw {
message:
'Invalid Shared Base ID :: Ensure www.airtable.com/<SharedBaseID> is accessible. Refer https://bit.ly/3x0OdXI for details',
};
}
const file = ft.schema; const file = ft.schema;
baseId = ft.baseId; baseId = ft.baseId;
base = new Airtable({ apiKey: sDB.apiKey }).base(baseId); base = new Airtable({ apiKey: sDB.apiKey }).base(baseId);

19
packages/nocodb/src/lib/meta/api/sync/importApis.ts

@ -107,14 +107,17 @@ export default (
baseURL = `http://localhost:${process.env.PORT || 8080}`; baseURL = `http://localhost:${process.env.PORT || 8080}`;
} }
NocoJobs.jobsMgr.add<AirtableSyncConfig>(AIRTABLE_IMPORT_JOB, { setTimeout(() => {
id: req.params.syncId, NocoJobs.jobsMgr.add<AirtableSyncConfig>(AIRTABLE_IMPORT_JOB, {
...(syncSource?.details || {}), id: req.params.syncId,
projectId: syncSource.project_id, ...(syncSource?.details || {}),
baseId: syncSource.base_id, projectId: syncSource.project_id,
authToken: token, baseId: syncSource.base_id,
baseURL, authToken: token,
}); baseURL,
});
}, 1000);
jobs[req.params.syncId] = { jobs[req.params.syncId] = {
last_message: { last_message: {
msg: 'Sync started', msg: 'Sync started',

Loading…
Cancel
Save