);
}
const AIError = ({
errorCode,
errorMessage,
}: {
errorCode?: string;
errorMessage: string;
}) => {
// NOTE: this error is not coming from the HTTP endpoint.
if (!errorCode) {
return <>{errorMessage}>;
}
// NOTE: this should never happen in Data Explorer as the frontend update would happen
// in coordination with the api changes.
if (errorCode === 'NOT_SUPPORTED') {
return (
<>
Sorry, this version of Compass is no longer suitable to generate
queries. Please update to the latest version to access all the features.
>
);
}
if (errorCode === 'USER_INPUT_TOO_LONG') {
return (
<>
Looks like your input exceeds the allowed length. Please reduce it and
submit your prompt again.
>
);
}
if (errorCode === 'PROMPT_TOO_LONG') {
// TODO: https://jira.mongodb.org/browse/COMPASS-6866,
// the following errors are probably better handled at service or backend level, by retrying the
// call without the schema and additional parameters, since users are not
// able to fix the issue on their own it cases where the schema is too big.
return (
<>
Sorry, your collections have too many fields to process. Please try
using this feature on a collection with smaller documents.
>
);
}
if (errorCode === 'TOO_MANY_REQUESTS') {
return (
<>
Sorry, we are receiving too many requests in a short period of time.
Please wait a few minutes and try again.
>
);
}
if (errorCode === 'GATEWAY_TIMEOUT') {
return (
<>
It took too long to generate your query, please check your connection
and try again. If the problem persists, contact our support team.
>
);
}
// We received an errorCode that is not actionable (INTERNAL_SERVER_ERROR, QUERY_GENERATION_FAILED), or unknown.
return (
<>
Sorry, we were unable to generate the query, please try again. If the
error persists, try changing your prompt.
>
);
};
export { GenerativeAIInput };