Improve the error display when a run cannot connect to an endpoint
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
import { TriggerClient } from "./triggerClient";
|
||||
import type {
|
||||
EventSpecification,
|
||||
Logger,
|
||||
Trigger,
|
||||
TriggerContext,
|
||||
TriggerEventType,
|
||||
|
||||
@@ -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`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user