Improve the error display when a run cannot connect to an endpoint

This commit is contained in:
Eric Allam
2023-07-07 15:32:15 +01:00
parent 4692cd6a55
commit 5ee0b188bd
5 changed files with 16 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---
Don't return the apiKey when they don't match
@@ -173,6 +173,7 @@ export class EndpointApi {
return {
response,
parser: RunJobResponseSchema,
errorParser: ErrorWithStackSchema,
};
}
@@ -247,7 +247,7 @@ export class PerformRunExecutionService {
run.event.sourceContext
);
const { response, parser } = await client.executeJobRequest({
const { response, parser, errorParser } = await client.executeJobRequest({
event,
job: {
id: run.version.job.slug,
@@ -288,13 +288,20 @@ export class PerformRunExecutionService {
});
}
const rawBody = await response.text();
if (!response.ok) {
const errorBody = safeJsonZodParse(errorParser, rawBody);
if (errorBody && errorBody.success) {
return await this.#failRunExecutionWithRetry(execution, errorBody.data);
}
return await this.#failRunExecutionWithRetry(execution, {
message: `Endpoint responded with ${response.status} status code`,
});
}
const rawBody = await response.text();
const safeBody = safeJsonZodParse(parser, rawBody);
if (!safeBody) {
-1
View File
@@ -12,7 +12,6 @@ import {
import { TriggerClient } from "./triggerClient";
import type {
EventSpecification,
Logger,
Trigger,
TriggerContext,
TriggerEventType,
+1 -3
View File
@@ -141,9 +141,7 @@ export class TriggerClient {
return {
status: 401,
body: {
message: `Forbidden: client apiKey mismatch: Expected ${
this.#options.apiKey
}, got ${apiKey}`,
message: `Forbidden: client apiKey mismatch: Make sure you are using the correct API Key for your environment`,
},
};
}