propagate errors coreectly for datasource plus
This commit is contained in:
parent
82bafacd72
commit
46a9142676
|
@ -10,6 +10,7 @@ import {
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
ConnectionInfo,
|
ConnectionInfo,
|
||||||
|
SourceName,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
@ -20,6 +21,7 @@ import {
|
||||||
} from "./utils"
|
} from "./utils"
|
||||||
import Sql from "./base/sql"
|
import Sql from "./base/sql"
|
||||||
import { MSSQLTablesResponse, MSSQLColumn } from "./base/types"
|
import { MSSQLTablesResponse, MSSQLColumn } from "./base/types"
|
||||||
|
import { getReadableErrorMessage } from "./base/errorMapping"
|
||||||
const sqlServer = require("mssql")
|
const sqlServer = require("mssql")
|
||||||
const DEFAULT_SCHEMA = "dbo"
|
const DEFAULT_SCHEMA = "dbo"
|
||||||
|
|
||||||
|
@ -177,9 +179,16 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
|
? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
|
||||||
: query.sql
|
: query.sql
|
||||||
return await request.query(sql)
|
return await request.query(sql)
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
// @ts-ignore
|
let readableMessage = getReadableErrorMessage(
|
||||||
throw new Error(err)
|
SourceName.SQL_SERVER,
|
||||||
|
err.errno
|
||||||
|
)
|
||||||
|
if (readableMessage) {
|
||||||
|
throw new Error(readableMessage)
|
||||||
|
} else {
|
||||||
|
throw new Error(err.message as string)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
ConnectionInfo,
|
ConnectionInfo,
|
||||||
|
SourceName,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
@ -21,7 +22,7 @@ import dayjs from "dayjs"
|
||||||
import { NUMBER_REGEX } from "../utilities"
|
import { NUMBER_REGEX } from "../utilities"
|
||||||
import Sql from "./base/sql"
|
import Sql from "./base/sql"
|
||||||
import { MySQLColumn } from "./base/types"
|
import { MySQLColumn } from "./base/types"
|
||||||
|
import { getReadableErrorMessage } from "./base/errorMapping"
|
||||||
import mysql from "mysql2/promise"
|
import mysql from "mysql2/promise"
|
||||||
|
|
||||||
interface MySQLConfig extends mysql.ConnectionOptions {
|
interface MySQLConfig extends mysql.ConnectionOptions {
|
||||||
|
@ -174,7 +175,12 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||||
)
|
)
|
||||||
response.connected = result?.checkRes == 2
|
response.connected = result?.checkRes == 2
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
response.error = e.message as string
|
let readableMessage = getReadableErrorMessage(SourceName.MYSQL, e.errno)
|
||||||
|
if (readableMessage) {
|
||||||
|
response.error = readableMessage
|
||||||
|
} else {
|
||||||
|
response.error = e.message as string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
@ -213,6 +219,13 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||||
// Node MySQL is callback based, so we must wrap our call in a promise
|
// Node MySQL is callback based, so we must wrap our call in a promise
|
||||||
const response = await this.client!.query(query.sql, bindings)
|
const response = await this.client!.query(query.sql, bindings)
|
||||||
return response[0]
|
return response[0]
|
||||||
|
} catch (err: any) {
|
||||||
|
let readableMessage = getReadableErrorMessage(SourceName.MYSQL, err.errno)
|
||||||
|
if (readableMessage) {
|
||||||
|
throw new Error(readableMessage)
|
||||||
|
} else {
|
||||||
|
throw new Error(err.message as string)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (opts?.connect && this.client) {
|
if (opts?.connect && this.client) {
|
||||||
await this.disconnect()
|
await this.disconnect()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
ConnectionInfo,
|
ConnectionInfo,
|
||||||
|
SourceName,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
@ -21,6 +22,7 @@ import { PostgresColumn } from "./base/types"
|
||||||
import { escapeDangerousCharacters } from "../utilities"
|
import { escapeDangerousCharacters } from "../utilities"
|
||||||
|
|
||||||
import { Client, ClientConfig, types } from "pg"
|
import { Client, ClientConfig, types } from "pg"
|
||||||
|
import { getReadableErrorMessage } from "./base/errorMapping"
|
||||||
|
|
||||||
// Return "date" and "timestamp" types as plain strings.
|
// Return "date" and "timestamp" types as plain strings.
|
||||||
// This lets us reference the original stored timezone.
|
// This lets us reference the original stored timezone.
|
||||||
|
@ -182,6 +184,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
await this.openConnection()
|
await this.openConnection()
|
||||||
response.connected = true
|
response.connected = true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
console.log(e)
|
||||||
response.error = e.message as string
|
response.error = e.message as string
|
||||||
} finally {
|
} finally {
|
||||||
await this.closeConnection()
|
await this.closeConnection()
|
||||||
|
@ -240,10 +243,17 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return await client.query(query.sql, query.bindings || [])
|
return await client.query(query.sql, query.bindings || [])
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
await this.closeConnection()
|
await this.closeConnection()
|
||||||
// @ts-ignore
|
let readableMessage = getReadableErrorMessage(
|
||||||
throw new Error(err)
|
SourceName.POSTGRES,
|
||||||
|
err.errno
|
||||||
|
)
|
||||||
|
if (readableMessage) {
|
||||||
|
throw new Error(readableMessage)
|
||||||
|
} else {
|
||||||
|
throw new Error(err.message as string)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (close) {
|
if (close) {
|
||||||
await this.closeConnection()
|
await this.closeConnection()
|
||||||
|
|
Loading…
Reference in New Issue