Skip to content

[AI Infra] Update logic for getConnectorById #229227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('getConnectorById', () => {
expect(actionsClient.get).toHaveBeenCalledTimes(1);
expect(actionsClient.get).toHaveBeenCalledWith({
id: connectorId,
throwIfSystemAction: true,
});
});

Expand All @@ -53,7 +52,7 @@ describe('getConnectorById', () => {

await expect(() => getConnectorById({ actionsClient, connectorId })).rejects
.toThrowErrorMatchingInlineSnapshot(`
"No connector found for id 'my-connector-id'
"An error occur fetching connectors for id 'my-connector-id'
Something wrong"
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { ActionsClient, ActionResult as ActionConnector } from '@kbn/actions-plugin/server';
import type { ActionsClient } from '@kbn/actions-plugin/server';
import {
createInferenceRequestError,
connectorToInference,
Expand All @@ -22,15 +22,15 @@ export const getConnectorById = async ({
actionsClient: ActionsClient;
connectorId: string;
}): Promise<InferenceConnector> => {
let connector: ActionConnector;
let connector;
try {
connector = await actionsClient.get({
id: connectorId,
throwIfSystemAction: true,
});
connector = await actionsClient.get({ id: connectorId });
if (!connector) {
throw createInferenceRequestError(`No connector found for id '${connectorId}'`, 400);
}
} catch (error) {
throw createInferenceRequestError(
`No connector found for id '${connectorId}'\n${error.message}`,
`An error occur fetching connectors for id '${connectorId}'\n${error.message}`,
400
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export const chatCompleteSuite = (
type: 'error',
code: 'requestError',
message:
"No connector found for id 'do-not-exist'\nSaved object [action/do-not-exist] not found",
"An error occur fetching connectors for id 'do-not-exist'\\nSaved object [action/do-not-exist] not found",
});
});

Expand Down Expand Up @@ -338,7 +338,7 @@ export const chatCompleteSuite = (
error: {
code: 'requestError',
message:
"No connector found for id 'do-not-exist'\nSaved object [action/do-not-exist] not found",
"An error occur fetching connectors for id 'do-not-exist'\\nSaved object [action/do-not-exist] not found",
meta: {
status: 400,
},
Expand Down