Better error messages if you haven’t set the API URL or SECRET for the v3 client

This commit is contained in:
Matt Aitken
2024-03-27 14:08:13 +00:00
parent 3a35d60091
commit fc473105e3
+18 -4
View File
@@ -214,7 +214,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
const apiClient = apiClientManager.client;
if (!apiClient) {
throw new Error("API client is not initialized");
throw apiClientMissingError();
}
const taskMetadata = runtime.getTaskMetadata(params.id);
@@ -273,7 +273,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
const apiClient = apiClientManager.client;
if (!apiClient) {
throw new Error("API client is not initialized");
throw apiClientMissingError();
}
const taskMetadata = runtime.getTaskMetadata(params.id);
@@ -343,7 +343,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
const apiClient = apiClientManager.client;
if (!apiClient) {
throw new Error("API client is not initialized");
throw apiClientMissingError();
}
const taskMetadata = runtime.getTaskMetadata(params.id);
@@ -414,7 +414,7 @@ export function createTask<TInput, TOutput, TInitOutput extends InitOutput>(
const apiClient = apiClientManager.client;
if (!apiClient) {
throw new Error("API client is not initialized");
throw apiClientMissingError();
}
const taskMetadata = runtime.getTaskMetadata(params.id);
@@ -558,3 +558,17 @@ async function handleTaskRunExecutionResult<TOutput>(
};
}
}
function apiClientMissingError() {
const hasBaseUrl = !!apiClientManager.baseURL;
const hasAccessToken = !!apiClientManager.accessToken;
if (!hasBaseUrl && !hasAccessToken) {
return `You need to set the TRIGGER_API_URL and TRIGGER_SECRET_KEY environment variables.`;
} else if (!hasBaseUrl) {
return `You need to set the TRIGGER_API_URL environment variable.`;
} else if (!hasAccessToken) {
return `You need to set the TRIGGER_SECRET_KEY environment variable.`;
}
return `Unknown error`;
}