diff --git a/connectors/src/api/bot_enabled.ts b/connectors/src/api/bot_enabled.ts index 261edbe0ccbc..ab03aad8840b 100644 --- a/connectors/src/api/bot_enabled.ts +++ b/connectors/src/api/bot_enabled.ts @@ -21,30 +21,30 @@ const _getBotEnabled = async ( ) => { if (!req.params.connector_id) { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: "Missing required parameters. Required: connector_id", }, - status_code: 400, }); } const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } if (connector.type !== "slack") { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: "Connector is not a slack connector", }, - status_code: 400, }); } @@ -54,11 +54,11 @@ const _getBotEnabled = async ( if (botEnabledRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: `An error occurred while getting the bot status: ${botEnabledRes.error}`, }, - status_code: 500, }); } return res.status(200).json({ @@ -72,30 +72,30 @@ const _setBotEnabled = async ( ) => { if (!req.params.connector_id) { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: "Missing required parameters. Required: connector_id", }, - status_code: 400, }); } const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } if (!req.body || typeof req.body.botEnabled !== "boolean") { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: "Missing required parameters. Required: botEnabled", }, - status_code: 400, }); } @@ -106,11 +106,11 @@ const _setBotEnabled = async ( if (toggleRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: `An error occurred while toggling the bot: ${toggleRes.error.message}`, }, - status_code: 500, }); } return res.status(200).json({ diff --git a/connectors/src/api/create_connector.ts b/connectors/src/api/create_connector.ts index ddf7b4e2ac85..9bfa324cd514 100644 --- a/connectors/src/api/create_connector.ts +++ b/connectors/src/api/create_connector.ts @@ -34,22 +34,22 @@ const _createConnectorAPIHandler = async ( !req.body.connectionId ) { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: `Missing required parameters. Required : workspaceAPIKey, dataSourceName, workspaceId, connectionId`, }, - status_code: 400, }); } if (!isConnectorProvider(req.params.connector_provider)) { return apiError(req, res, { + status_code: 400, api_error: { type: "unknown_connector_provider", message: `Unknown connector provider ${req.params.connector_provider}`, }, - status_code: 400, }); } @@ -67,22 +67,22 @@ const _createConnectorAPIHandler = async ( if (connectorRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: connectorRes.error.message, }, - status_code: 500, }); } const connector = await Connector.findByPk(connectorRes.value); if (!connector) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: `Created connector not found in database. Connector id: ${connectorRes.value}`, }, - status_code: 500, }); } @@ -101,11 +101,11 @@ const _createConnectorAPIHandler = async ( } catch (e) { logger.error(errorFromAny(e), "Error in createConnectorAPIHandler"); return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: "An unexpected error occured while creating the connector.", }, - status_code: 500, }); } }; diff --git a/connectors/src/api/delete_connector.ts b/connectors/src/api/delete_connector.ts index 6ba89d62da34..ceecbade75cb 100644 --- a/connectors/src/api/delete_connector.ts +++ b/connectors/src/api/delete_connector.ts @@ -27,11 +27,11 @@ const _deleteConnectorAPIHandler = async ( const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } @@ -41,21 +41,21 @@ const _deleteConnectorAPIHandler = async ( if (stopRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: stopRes.error.message, }, - status_code: 500, }); } if (!connector) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: "Could not find the connector", }, - status_code: 500, }); } @@ -63,11 +63,11 @@ const _deleteConnectorAPIHandler = async ( const cleanRes = await connectorDeleter(connector.id.toString(), force); if (cleanRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: cleanRes.error.message, }, - status_code: 500, }); } diff --git a/connectors/src/api/get_connector_permissions.ts b/connectors/src/api/get_connector_permissions.ts index 0fe9a13b53e7..83855e08ae58 100644 --- a/connectors/src/api/get_connector_permissions.ts +++ b/connectors/src/api/get_connector_permissions.ts @@ -19,11 +19,11 @@ const _getConnectorPermissions = async ( ) => { if (!req.params.connector_id) { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: "Missing required parameters. Required: connector_id", }, - status_code: 400, }); } @@ -50,11 +50,11 @@ const _getConnectorPermissions = async ( const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } @@ -69,11 +69,11 @@ const _getConnectorPermissions = async ( if (pRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: pRes.error.message, }, - status_code: 500, }); } diff --git a/connectors/src/api/get_resources_parents.ts b/connectors/src/api/get_resources_parents.ts index d202195b46d6..34c550d7ef45 100644 --- a/connectors/src/api/get_resources_parents.ts +++ b/connectors/src/api/get_resources_parents.ts @@ -35,11 +35,11 @@ const _getResourcesParents = async ( const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } @@ -47,11 +47,11 @@ const _getResourcesParents = async ( if (isLeft(bodyValidation)) { const pathError = reporter.formatValidationErrors(bodyValidation.left); return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: `Invalid request body: ${pathError}`, }, - status_code: 400, }); } @@ -72,11 +72,11 @@ const _getResourcesParents = async ( if (parentsResult.isErr()) { logger.error(parentsResult.error, "Failed to get resource parents"); return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: parentsResult.error.message, }, - status_code: 500, }); } diff --git a/connectors/src/api/get_resources_titles.ts b/connectors/src/api/get_resources_titles.ts index 6f5f188033d5..d2a2794c9b81 100644 --- a/connectors/src/api/get_resources_titles.ts +++ b/connectors/src/api/get_resources_titles.ts @@ -33,11 +33,11 @@ const _getResourcesTitles = async ( const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } @@ -45,11 +45,11 @@ const _getResourcesTitles = async ( if (isLeft(bodyValidation)) { const pathError = reporter.formatValidationErrors(bodyValidation.left); return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: `Invalid request body: ${pathError}`, }, - status_code: 400, }); } @@ -65,11 +65,11 @@ const _getResourcesTitles = async ( if (titlesRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: titlesRes.error.message, }, - status_code: 500, }); } diff --git a/connectors/src/api/resume_connector.ts b/connectors/src/api/resume_connector.ts index 62f98e60f863..b4ece02e03ff 100644 --- a/connectors/src/api/resume_connector.ts +++ b/connectors/src/api/resume_connector.ts @@ -19,11 +19,11 @@ const _resumeConnectorAPIHandler = async ( const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } const connectorResumer = RESUME_CONNECTOR_BY_TYPE[connector.type]; @@ -32,11 +32,11 @@ const _resumeConnectorAPIHandler = async ( if (resumeRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: "Could not resume the connector", }, - status_code: 500, }); } @@ -46,11 +46,11 @@ const _resumeConnectorAPIHandler = async ( } catch (e) { logger.error(errorFromAny(e), "Failed to resume the connector"); return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: "Could not resume the connector", }, - status_code: 500, }); } }; diff --git a/connectors/src/api/set_connector_permissions.ts b/connectors/src/api/set_connector_permissions.ts index d8add128a7bb..824d56dd2b00 100644 --- a/connectors/src/api/set_connector_permissions.ts +++ b/connectors/src/api/set_connector_permissions.ts @@ -39,11 +39,11 @@ const _setConnectorPermissions = async ( ) => { if (!req.params.connector_id) { return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: "Missing required parameters. Required: connector_id", }, - status_code: 400, }); } @@ -54,11 +54,11 @@ const _setConnectorPermissions = async ( if (isLeft(bodyValidation)) { const pathError = reporter.formatValidationErrors(bodyValidation.left); return apiError(req, res, { + status_code: 400, api_error: { type: "invalid_request_error", message: `Invalid request body: ${pathError}`, }, - status_code: 400, }); } @@ -67,11 +67,11 @@ const _setConnectorPermissions = async ( const connector = await Connector.findByPk(req.params.connector_id); if (!connector) { return apiError(req, res, { + status_code: 404, api_error: { type: "connector_not_found", message: "Connector not found", }, - status_code: 404, }); } @@ -88,11 +88,11 @@ const _setConnectorPermissions = async ( if (pRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: pRes.error.message, }, - status_code: 500, }); } diff --git a/connectors/src/api/slack_channels_linked_with_agent.ts b/connectors/src/api/slack_channels_linked_with_agent.ts index 10d7be270f2a..6c5c844327cc 100644 --- a/connectors/src/api/slack_channels_linked_with_agent.ts +++ b/connectors/src/api/slack_channels_linked_with_agent.ts @@ -131,11 +131,11 @@ const _patchSlackChannelsLinkedWithAgentHandler = async ( req, res, { + status_code: 400, api_error: { - type: "internal_server_error", + type: "connector_update_error", message: `Could not join channel: ${joinRes.error}`, }, - status_code: 400, }, joinRes.error ); diff --git a/connectors/src/api/stop_connector.ts b/connectors/src/api/stop_connector.ts index 69221cc38319..69819362d3cb 100644 --- a/connectors/src/api/stop_connector.ts +++ b/connectors/src/api/stop_connector.ts @@ -32,11 +32,11 @@ const _stopConnectorAPIHandler = async ( if (stopRes.isErr()) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: stopRes.error.message, }, - status_code: 500, }); } @@ -46,11 +46,11 @@ const _stopConnectorAPIHandler = async ( } catch (e) { logger.error(errorFromAny(e), "Failed to stop the connector"); return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: "Could not stop the connector", }, - status_code: 500, }); } }; diff --git a/connectors/src/api/update_connector.ts b/connectors/src/api/update_connector.ts index 35344c893a83..36263fd884d3 100644 --- a/connectors/src/api/update_connector.ts +++ b/connectors/src/api/update_connector.ts @@ -59,11 +59,11 @@ const _getConnectorUpdateAPIHandler = async ( }); } else { return apiError(req, res, { + status_code: 500, api_error: { - type: "connector_update_error", + type: "internal_server_error", message: `Could not update the connector: ${error.message}`, }, - status_code: 500, }); } } diff --git a/connectors/src/api/webhooks/webhook_google_drive.ts b/connectors/src/api/webhooks/webhook_google_drive.ts index 5275ce422d0e..86bc779b2292 100644 --- a/connectors/src/api/webhooks/webhook_google_drive.ts +++ b/connectors/src/api/webhooks/webhook_google_drive.ts @@ -43,8 +43,8 @@ const _webhookGoogleDriveAPIHandler = async ( return apiError(req, res, { status_code: 500, api_error: { + type: "internal_server_error", message: `Failed starting the incremental sync workflow. Error: ${workflowRes.error.message}`, - type: "invalid_request_error", }, }); } diff --git a/connectors/src/api/webhooks/webhook_slack.ts b/connectors/src/api/webhooks/webhook_slack.ts index 73fc5457c5a0..19552a36c5fd 100644 --- a/connectors/src/api/webhooks/webhook_slack.ts +++ b/connectors/src/api/webhooks/webhook_slack.ts @@ -300,11 +300,11 @@ const _webhookSlackAPIHandler = async ( if (err) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: err.message, }, - status_code: 500, }); } else { logger.info( @@ -354,11 +354,11 @@ const _webhookSlackAPIHandler = async ( if (err) { return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", message: err.message, }, - status_code: 500, }); } else { logger.info( diff --git a/connectors/src/middleware/auth.ts b/connectors/src/middleware/auth.ts index 52eb2f1b8246..c00b8471e877 100644 --- a/connectors/src/middleware/auth.ts +++ b/connectors/src/middleware/auth.ts @@ -106,11 +106,11 @@ const _authMiddlewareWebhooksGithub = ( if (!GITHUB_WEBHOOK_SECRET) { logger.error("GITHUB_WEBHOOK_SECRET is not defined"); return apiError(req, res, { + status_code: 500, api_error: { type: "internal_server_error", - message: "Internal server error.", + message: "Webhook secret is not defined.", }, - status_code: 500, }); } diff --git a/front/lib/api/assistant/reaction.ts b/front/lib/api/assistant/reaction.ts index 02bd33420e09..9dc29b0e376d 100644 --- a/front/lib/api/assistant/reaction.ts +++ b/front/lib/api/assistant/reaction.ts @@ -14,7 +14,7 @@ import { UserType } from "@app/types/user"; export async function getMessageReactions( auth: Authenticator, conversation: ConversationType | ConversationWithoutContentType -): Promise { +): Promise { const owner = auth.workspace(); if (!owner) { throw new Error("Unexpected `auth` without `workspace`."); diff --git a/front/lib/error.ts b/front/lib/error.ts index ac90e1cfed38..e77abc6e6d2f 100644 --- a/front/lib/error.ts +++ b/front/lib/error.ts @@ -44,12 +44,8 @@ export type APIErrorType = | "conversation_not_found" | "agent_configuration_not_found" | "message_not_found" - | "message_reaction_error" | "test_plan_message_limit_reached" | "global_agent_error" - | "subscription_error" - | "stripe_webhook_error" - | "stripe_api_error" | "stripe_invalid_product_id_error" | "rate_limit_error"; diff --git a/front/pages/api/stripe/portal.ts b/front/pages/api/stripe/portal.ts index f3ba5a85bf01..9d1de4f7a5b3 100644 --- a/front/pages/api/stripe/portal.ts +++ b/front/pages/api/stripe/portal.ts @@ -70,8 +70,9 @@ async function handler( return apiError(req, res, { status_code: 500, api_error: { - type: "stripe_api_error", - message: "An error occured while fetching the customer portal url.", + type: "internal_server_error", + message: + "Stripe API: An error occured while fetching the customer portal url.", }, }); diff --git a/front/pages/api/stripe/webhook.ts b/front/pages/api/stripe/webhook.ts index 7f07d3e1bc5c..e345a2b7488a 100644 --- a/front/pages/api/stripe/webhook.ts +++ b/front/pages/api/stripe/webhook.ts @@ -27,16 +27,6 @@ async function handler( req: NextApiRequest, res: NextApiResponse ): Promise { - if (!STRIPE_SECRET_WEBHOOK_KEY || !STRIPE_SECRET_KEY) { - return apiError(req, res, { - status_code: 500, - api_error: { - type: "stripe_webhook_error", - message: "Stripe keys are not defined.", - }, - }); - } - const stripe = new Stripe(STRIPE_SECRET_KEY, { apiVersion: "2023-10-16", typescript: true, @@ -74,8 +64,8 @@ async function handler( return apiError(req, res, { status_code: 500, api_error: { - type: "stripe_webhook_error", - message: "Error constructing event.", + type: "internal_server_error", + message: "Error constructing Stripe Webhook event.", }, }); } @@ -255,8 +245,9 @@ async function handler( return apiError(req, res, { status_code: 500, api_error: { - type: "stripe_webhook_error", - message: "Error handling checkout.session.completed.", + type: "internal_server_error", + message: + "Stripe Webhook: error handling checkout.session.completed.", }, }); } @@ -299,9 +290,9 @@ async function handler( return apiError(req, res, { status_code: 500, api_error: { - type: "stripe_webhook_error", + type: "internal_server_error", message: - "Error handling customer.subscription.deleted. Subscription not found.", + "Stripe Webhook: Error handling customer.subscription.deleted. Subscription not found.", }, }); } diff --git a/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts b/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts index 5ad9f93a6077..9e305f2ea87b 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/[cId]/messages/[mId]/reactions/index.ts @@ -128,10 +128,10 @@ async function handler( return; } return apiError(req, res, { - status_code: 500, + status_code: 400, api_error: { - type: "message_reaction_error", - message: "Message reaction not created.", + type: "invalid_request_error", + message: "The message you're trying to react to does not exist.", }, }); @@ -151,10 +151,10 @@ async function handler( res.status(200).json({ success: true }); } return apiError(req, res, { - status_code: 500, + status_code: 400, api_error: { - type: "message_reaction_error", - message: "Message reaction not deleted.", + type: "invalid_request_error", + message: "The message you're trying to react to does not exist.", }, }); diff --git a/front/pages/api/w/[wId]/assistant/conversations/[cId]/reactions.ts b/front/pages/api/w/[wId]/assistant/conversations/[cId]/reactions.ts index f51a6a090b19..809731dd3568 100644 --- a/front/pages/api/w/[wId]/assistant/conversations/[cId]/reactions.ts +++ b/front/pages/api/w/[wId]/assistant/conversations/[cId]/reactions.ts @@ -78,17 +78,9 @@ async function handler( switch (req.method) { case "GET": const reactions = await getMessageReactions(auth, conversation); - if (reactions) { - res.status(200).json({ reactions }); - return; - } - return apiError(req, res, { - status_code: 500, - api_error: { - type: "message_reaction_error", - message: "Couldn't load message reactions.", - }, - }); + + res.status(200).json({ reactions }); + return; default: return apiError(req, res, { diff --git a/front/pages/api/w/[wId]/data_sources/[name]/managed/update.ts b/front/pages/api/w/[wId]/data_sources/[name]/managed/update.ts index f5cae1c5cfe5..b907b3cab4ca 100644 --- a/front/pages/api/w/[wId]/data_sources/[name]/managed/update.ts +++ b/front/pages/api/w/[wId]/data_sources/[name]/managed/update.ts @@ -126,11 +126,11 @@ async function handler( }); } else { return apiError(req, res, { + status_code: 500, api_error: { - type: "connector_update_error", + type: "internal_server_error", message: `Could not update the connector: ${error.message}`, }, - status_code: 500, }); } } diff --git a/front/pages/api/w/[wId]/subscriptions/index.ts b/front/pages/api/w/[wId]/subscriptions/index.ts index e4901216c6de..68c064e6cf97 100644 --- a/front/pages/api/w/[wId]/subscriptions/index.ts +++ b/front/pages/api/w/[wId]/subscriptions/index.ts @@ -60,7 +60,7 @@ async function handler( return apiError(req, res, { status_code: 500, api_error: { - type: "subscription_error", + type: "internal_server_error", message: "Error while subscribing workspace to plan", }, }); @@ -78,7 +78,7 @@ async function handler( return apiError(req, res, { status_code: 500, api_error: { - type: "subscription_error", + type: "internal_server_error", message: "Error while downgrading workspace to free plan", }, });