This also improves the retrying behavior of the resend integration by skipping retrying certain client errors
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@trigger.dev/resend": patch
|
||||
"@trigger.dev/core": patch
|
||||
---
|
||||
|
||||
Allow task property values to be blank, but strip them out before persisting them
|
||||
@@ -280,7 +280,7 @@ export class RunTaskService {
|
||||
noop: taskBody.noop,
|
||||
delayUntil: taskBody.delayUntil,
|
||||
params: taskBody.params ?? undefined,
|
||||
properties: taskBody.properties ?? undefined,
|
||||
properties: this.#filterProperties(taskBody.properties) ?? undefined,
|
||||
redact: taskBody.redact ?? undefined,
|
||||
operation: taskBody.operation,
|
||||
callbackUrl,
|
||||
@@ -325,4 +325,14 @@ export class RunTaskService {
|
||||
|
||||
return task ? taskWithAttemptsToServerTask(task) : undefined;
|
||||
}
|
||||
|
||||
#filterProperties(properties: RunTaskBodyOutput["properties"]): RunTaskBodyOutput["properties"] {
|
||||
if (!properties) return;
|
||||
|
||||
return properties.filter((property) => {
|
||||
if (!property) return false;
|
||||
|
||||
return typeof property.label === "string" && typeof property.text === "string";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@ The wrappers at `io.integration.runTask()` expose the underlying Integration cli
|
||||
The value of the property.
|
||||
</ResponseField>
|
||||
</Expandable>
|
||||
|
||||
</ResponseField>
|
||||
|
||||
</Expandable>
|
||||
@@ -135,7 +136,7 @@ The wrappers at `io.integration.runTask()` expose the underlying Integration cli
|
||||
|
||||
<ResponseField name="onError" type="function">
|
||||
An optional callback that will be called when the Task fails. You can perform
|
||||
logic in here and optionally return a custom error object. Returning an object with `{ retryAt: Date, error?: Error }` will retry the Task at the specified Date. You can also just return a new `Error` object to throw a new error. Return nothing to rethrow the original error.
|
||||
logic in here and optionally return a custom error object. Returning an object with `{ retryAt: Date, error?: Error }` will retry the Task at the specified Date. You can also just return a new `Error` object to throw a new error. Returning `null` or `undefined` will rethrow the original error. If you want to force retrying to be skipped, return `{ skipRetrying: true }`.
|
||||
|
||||
<Expandable title="arguments">
|
||||
<ResponseField name="error" type="unknown">
|
||||
|
||||
@@ -25,6 +25,9 @@ function isRequestError(error: unknown): error is ErrorResponse {
|
||||
return typeof error === "object" && error !== null && "statusCode" in error;
|
||||
}
|
||||
|
||||
// See https://resend.com/docs/api-reference/errors
|
||||
const skipRetryingErrors = [422, 401, 403, 404, 405, 422];
|
||||
|
||||
function onError(error: unknown) {
|
||||
if (!isRequestError(error)) {
|
||||
if (error instanceof Error) {
|
||||
@@ -34,6 +37,12 @@ function onError(error: unknown) {
|
||||
return new Error("Unknown error");
|
||||
}
|
||||
|
||||
if (skipRetryingErrors.includes(error.statusCode)) {
|
||||
return {
|
||||
skipRetrying: true,
|
||||
};
|
||||
}
|
||||
|
||||
return new Error(error.message);
|
||||
}
|
||||
|
||||
|
||||
@@ -664,6 +664,7 @@ export const RunTaskBodyInputSchema = RunTaskOptionsSchema.extend({
|
||||
export type RunTaskBodyInput = z.infer<typeof RunTaskBodyInputSchema>;
|
||||
|
||||
export const RunTaskBodyOutputSchema = RunTaskBodyInputSchema.extend({
|
||||
properties: z.array(DisplayPropertySchema.partial()).optional(),
|
||||
params: DeserializedJsonSchema.optional().nullable(),
|
||||
callback: z
|
||||
.object({
|
||||
|
||||
@@ -43,4 +43,32 @@ client.defineJob({
|
||||
},
|
||||
});
|
||||
|
||||
client.defineJob({
|
||||
id: "send-resend-email-from-blank",
|
||||
name: "Send Resend Email From Blank",
|
||||
version: "0.1.0",
|
||||
trigger: eventTrigger({
|
||||
name: "send.email",
|
||||
schema: z.object({
|
||||
to: z.union([z.string(), z.array(z.string())]),
|
||||
subject: z.string(),
|
||||
text: z.string(),
|
||||
from: z.string().optional(),
|
||||
}),
|
||||
}),
|
||||
integrations: {
|
||||
resend,
|
||||
},
|
||||
run: async (payload, io, ctx) => {
|
||||
const response = await io.resend.sendEmail("📧", {
|
||||
to: payload.to,
|
||||
subject: payload.subject,
|
||||
text: payload.text,
|
||||
from: payload.from!,
|
||||
});
|
||||
|
||||
await io.logger.info("Sent email", { response });
|
||||
},
|
||||
});
|
||||
|
||||
createExpressServer(client);
|
||||
|
||||
Reference in New Issue
Block a user