Merge master.

This commit is contained in:
Sam Rose 2025-04-29 12:12:55 +01:00
commit d23d0f59bd
No known key found for this signature in database
7 changed files with 29 additions and 33 deletions

View File

@ -1,5 +1,7 @@
// BASE
import { ErrorCode } from "@budibase/types"
export abstract class BudibaseError extends Error {
code: string
@ -13,13 +15,6 @@ export abstract class BudibaseError extends Error {
// ERROR HANDLING
export enum ErrorCode {
USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
FEATURE_DISABLED = "feature_disabled",
INVALID_API_KEY = "invalid_api_key",
HTTP = "http",
}
/**
* For the given error, build the public representation that is safe
* to be exposed over an api.

View File

@ -16,11 +16,12 @@ import env from "../environment"
import {
Ctx,
EndpointMatcher,
ErrorCode,
LoginMethod,
SessionCookie,
User,
} from "@budibase/types"
import { ErrorCode, InvalidAPIKeyError } from "../errors"
import { InvalidAPIKeyError } from "../errors"
import tracer from "dd-trace"
import type { Middleware, Next } from "koa"

View File

@ -3,7 +3,7 @@
import { createEventDispatcher } from "svelte"
import { API } from "@/api"
import type { EnrichedBinding } from "@budibase/types"
import { ErrorCode, type EnrichedBinding } from "@budibase/types"
import analytics, { Events } from "@/analytics"
import AiInput from "../ai/AIInput.svelte"
@ -43,17 +43,26 @@
const resp = await API.generateJs({ prompt, bindings })
const code = resp.code
if (code === "") {
throw new Error("We didn't understand your prompt. Please rephrase it.")
throw new Error(
"We didn't understand your prompt. This can happen if the prompt isn't specific, or if it's a request for something other than code. Try expressing your request in a different way."
)
}
suggestedCode = code
dispatch("update", { code })
} catch (e) {
console.error(e)
notifications.error(
e instanceof Error
? `Unable to generate code: ${e.message}`
: "Unable to generate code. Please try again later."
)
if (!(e instanceof Error)) {
notifications.error("Unable to generate code. Please try again later.")
return
}
if ("code" in e && e.code === ErrorCode.USAGE_LIMIT_EXCEEDED) {
notifications.error(
"Monthly usage limit reached. We're exploring options to expand this soon. Questions? Contact support@budibase.com"
)
} else {
notifications.error(`Unable to generate code: ${e.message}`)
}
}
}

View File

@ -26,7 +26,6 @@ import {
db as dbCore,
docIds,
env as envCore,
ErrorCode,
events,
objectStore,
roles,
@ -70,6 +69,7 @@ import {
AddAppSampleDataResponse,
UnpublishAppResponse,
SetRevertableAppVersionResponse,
ErrorCode,
} from "@budibase/types"
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
import sdk from "../../sdk"

View File

@ -4,3 +4,10 @@ export interface APIError {
error?: any
validationErrors?: any
}
export enum ErrorCode {
USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
FEATURE_DISABLED = "feature_disabled",
INVALID_API_KEY = "invalid_api_key",
HTTP = "http",
}

View File

@ -32,14 +32,12 @@ import {
OIDCConfigs,
OIDCLogosConfig,
PASSWORD_REPLACEMENT,
QuotaUsageType,
SaveConfigRequest,
SaveConfigResponse,
SettingsBrandingConfig,
SettingsInnerConfig,
SSOConfig,
SSOConfigType,
StaticQuotaName,
UploadConfigFileResponse,
UserCtx,
} from "@budibase/types"
@ -53,7 +51,6 @@ const getEventFns = async (config: Config, existing?: Config) => {
fns.push(events.email.SMTPCreated)
} else if (isAIConfig(config)) {
fns.push(() => events.ai.AIConfigCreated)
fns.push(() => pro.quotas.addCustomAIConfig())
} else if (isGoogleConfig(config)) {
fns.push(() => events.auth.SSOCreated(ConfigType.GOOGLE))
if (config.config.activated) {
@ -92,12 +89,6 @@ const getEventFns = async (config: Config, existing?: Config) => {
fns.push(events.email.SMTPUpdated)
} else if (isAIConfig(config)) {
fns.push(() => events.ai.AIConfigUpdated)
if (
Object.keys(existing.config).length > Object.keys(config.config).length
) {
fns.push(() => pro.quotas.removeCustomAIConfig())
}
fns.push(() => pro.quotas.addCustomAIConfig())
} else if (isGoogleConfig(config)) {
fns.push(() => events.auth.SSOUpdated(ConfigType.GOOGLE))
if (!existing.config.activated && config.config.activated) {
@ -576,13 +567,6 @@ export async function destroy(ctx: UserCtx<void, DeleteConfigResponse>) {
try {
await db.remove(id, rev)
await cache.destroy(cache.CacheKey.CHECKLIST)
if (id === configs.generateConfigID(ConfigType.AI)) {
await pro.quotas.set(
StaticQuotaName.AI_CUSTOM_CONFIGS,
QuotaUsageType.STATIC,
0
)
}
ctx.body = { message: "Config deleted successfully" }
} catch (err: any) {
ctx.throw(err.status, err)

View File

@ -16,6 +16,7 @@ import {
DeleteInviteUsersRequest,
DeleteInviteUsersResponse,
DeleteUserResponse,
ErrorCode,
FetchUsersResponse,
FindUserResponse,
GetUserInvitesResponse,
@ -42,7 +43,6 @@ import {
import {
users,
cache,
ErrorCode,
events,
platform,
tenancy,