1
0
Fork 0
mirror of synced 2024-08-07 22:28:15 +12:00

Wire up the frontend to show the new datasource errors.

This commit is contained in:
Sam Rose 2023-10-16 16:36:42 +01:00
parent 37fe91e488
commit b7ff1d60f1
3 changed files with 27 additions and 33 deletions

View file

@ -1,6 +1,6 @@
import { derived, writable, get } from "svelte/store" import { derived, writable, get } from "svelte/store"
import { keepOpen, notifications } from "@budibase/bbui" import { keepOpen, notifications } from "@budibase/bbui"
import { datasources, ImportTableError, tables } from "stores/backend" import { datasources, tables } from "stores/backend"
export const createTableSelectionStore = (integration, datasource) => { export const createTableSelectionStore = (integration, datasource) => {
const tableNamesStore = writable([]) const tableNamesStore = writable([])
@ -30,12 +30,7 @@ export const createTableSelectionStore = (integration, datasource) => {
notifications.success(`Tables fetched successfully.`) notifications.success(`Tables fetched successfully.`)
await onComplete() await onComplete()
} catch (err) { } catch (err) {
if (err instanceof ImportTableError) {
errorStore.set(err) errorStore.set(err)
} else {
notifications.error("Error fetching tables.")
}
return keepOpen return keepOpen
} }
} }

View file

@ -9,15 +9,23 @@ import { API } from "api"
import { DatasourceFeature } from "@budibase/types" import { DatasourceFeature } from "@budibase/types"
import { TableNames } from "constants" import { TableNames } from "constants"
export class ImportTableError extends Error { class TableImportError extends Error {
constructor(message) { constructor(errors) {
super(message) super(`Error importing tables: ${Object.keys(errors).join(", ")}`)
const [title, description] = message.split(" - ") this.name = "TableImportError"
this.errors = errors
}
this.name = "TableSelectionError" get title() {
// Capitalize the first character of both the title and description return `Error fetching tables`
this.title = title[0].toUpperCase() + title.substr(1) }
this.description = description[0].toUpperCase() + description.substr(1)
get description() {
let message = ""
for (const key in this.errors) {
message += `${key}: ${this.errors[key]}\n`
}
return message
} }
} }
@ -78,9 +86,9 @@ export function createDatasourcesStore() {
} }
const updateDatasource = response => { const updateDatasource = response => {
const { datasource, error } = response const { datasource, errors } = response
if (error) { if (errors && Object.keys(errors).length > 0) {
store.update(state => ({ ...state })) throw new TableImportError(errors)
} }
replaceDatasource(datasource._id, datasource) replaceDatasource(datasource._id, datasource)
select(datasource._id) select(datasource._id)
@ -88,20 +96,11 @@ export function createDatasourcesStore() {
} }
const updateSchema = async (datasource, tablesFilter) => { const updateSchema = async (datasource, tablesFilter) => {
try {
const response = await API.buildDatasourceSchema({ const response = await API.buildDatasourceSchema({
datasourceId: datasource?._id, datasourceId: datasource?._id,
tablesFilter, tablesFilter,
}) })
updateDatasource(response) updateDatasource(response)
} catch (e) {
// buildDatasourceSchema call returns user presentable errors with two parts divided with a " - ".
if (e.message.split(" - ").length === 2) {
throw new ImportTableError(e.message)
} else {
throw e
}
}
} }
const sourceCount = source => { const sourceCount = source => {

View file

@ -4,7 +4,7 @@ export { views } from "./views"
export { viewsV2 } from "./viewsV2" export { viewsV2 } from "./viewsV2"
export { permissions } from "./permissions" export { permissions } from "./permissions"
export { roles } from "./roles" export { roles } from "./roles"
export { datasources, ImportTableError } from "./datasources" export { datasources } from "./datasources"
export { integrations } from "./integrations" export { integrations } from "./integrations"
export { sortedIntegrations } from "./sortedIntegrations" export { sortedIntegrations } from "./sortedIntegrations"
export { queries } from "./queries" export { queries } from "./queries"