@@ -181,7 +181,7 @@ This function is called before a run attempt:
181
181
``` ts /trigger/init.ts
182
182
export const taskWithInit = task ({
183
183
id: " task-with-init" ,
184
- init : async (payload , { ctx }) => {
184
+ init : async ({ payload , ctx }) => {
185
185
// ...
186
186
},
187
187
run : async (payload : any , { ctx }) => {
@@ -195,7 +195,7 @@ You can also return data from the `init` function that will be available in the
195
195
``` ts /trigger/init-return.ts
196
196
export const taskWithInitReturn = task ({
197
197
id: " task-with-init-return" ,
198
- init : async (payload , { ctx }) => {
198
+ init : async ({ payload , ctx }) => {
199
199
return { someData: " someValue" };
200
200
},
201
201
run : async (payload : any , { ctx , init }) => {
@@ -213,7 +213,7 @@ This function is called after the `run` function is executed, regardless of whet
213
213
``` ts /trigger/cleanup.ts
214
214
export const taskWithCleanup = task ({
215
215
id: " task-with-cleanup" ,
216
- cleanup : async (payload , { ctx }) => {
216
+ cleanup : async ({ payload , ctx }) => {
217
217
// ...
218
218
},
219
219
run : async (payload : any , { ctx }) => {
@@ -230,7 +230,7 @@ Our task middleware system runs at the top level, executing before and after all
230
230
231
231
<Info >
232
232
An error thrown in ` middleware ` is just like an uncaught error in the run function: it will
233
- propagate through to ` handleError ()` and then will fail the attempt (causing a retry).
233
+ propagate through to ` catchError ()` function and then will fail the attempt (causing a retry).
234
234
</Info >
235
235
236
236
The ` locals ` API allows you to share data between middleware and hooks.
@@ -303,7 +303,7 @@ When a task run starts, the `onStart` function is called. It's useful for sendin
303
303
``` ts /trigger/on-start.ts
304
304
export const taskWithOnStart = task ({
305
305
id: " task-with-on-start" ,
306
- onStart : async (payload , { ctx }) => {
306
+ onStart : async ({ payload , ctx }) => {
307
307
// ...
308
308
},
309
309
run : async (payload : any , { ctx }) => {
@@ -319,7 +319,7 @@ import { defineConfig } from "@trigger.dev/sdk";
319
319
320
320
export default defineConfig ({
321
321
project: " proj_1234" ,
322
- onStart : async (payload , { ctx }) => {
322
+ onStart : async ({ payload , ctx }) => {
323
323
console .log (" Task started" , ctx .task .id );
324
324
},
325
325
});
@@ -357,7 +357,7 @@ When a task run succeeds, the `onSuccess` function is called. It's useful for se
357
357
``` ts /trigger/on-success.ts
358
358
export const taskWithOnSuccess = task ({
359
359
id: " task-with-on-success" ,
360
- onSuccess : async (payload , output , { ctx }) => {
360
+ onSuccess : async ({ payload , output , ctx }) => {
361
361
// ...
362
362
},
363
363
run : async (payload : any , { ctx }) => {
@@ -373,7 +373,7 @@ import { defineConfig } from "@trigger.dev/sdk";
373
373
374
374
export default defineConfig ({
375
375
project: " proj_1234" ,
376
- onSuccess : async (payload , output , { ctx }) => {
376
+ onSuccess : async ({ payload , output , ctx }) => {
377
377
console .log (" Task succeeded" , ctx .task .id );
378
378
},
379
379
});
@@ -388,7 +388,7 @@ This hook is executed when a run completes, regardless of whether it succeeded o
388
388
``` ts /trigger/on-complete.ts
389
389
export const taskWithOnComplete = task ({
390
390
id: " task-with-on-complete" ,
391
- onComplete : async (payload , output , { ctx }) => {
391
+ onComplete : async ({ payload , output , ctx }) => {
392
392
if (result .ok ) {
393
393
console .log (" Run succeeded" , result .data );
394
394
} else {
@@ -404,7 +404,7 @@ When a task run fails, the `onFailure` function is called. It's useful for sendi
404
404
` ` ` ts / trigger / on - failure .ts
405
405
export const taskWithOnFailure = task ({
406
406
id: " task-with-on-failure" ,
407
- onFailure : async (payload , error , { ctx }) => {
407
+ onFailure : async ({ payload , error , ctx }) => {
408
408
// ...
409
409
},
410
410
run : async (payload : any , { ctx }) => {
@@ -420,7 +420,7 @@ import { defineConfig } from "@trigger.dev/sdk";
420
420
421
421
export default defineConfig ({
422
422
project: " proj_1234" ,
423
- onFailure : async (payload , error , { ctx }) => {
423
+ onFailure : async ({ payload , error , ctx }) => {
424
424
console .log (" Task failed" , ctx .task .id );
425
425
},
426
426
});
@@ -429,14 +429,15 @@ export default defineConfig({
429
429
<Info>Errors thrown in the ` onFailure ` function are ignored.</Info>
430
430
431
431
<Note>
432
- ` onFailure ` doesn’t fire for some of the run statuses like ` Crashed ` , ` System failures ` , and ` Canceled ` .
432
+ ` onFailure ` doesn’t fire for some of the run statuses like ` Crashed ` , ` System failures ` , and
433
+ ` Canceled ` .
433
434
</Note>
434
435
435
- ### ` handleError ` functions
436
+ ### ` catchError ` functions
436
437
437
438
You can define a function that will be called when an error is thrown in the ` run ` function, that allows you to control how the error is handled and whether the task should be retried.
438
439
439
- Read more about ` handleError ` in our [Errors and Retrying guide](/errors-retrying).
440
+ Read more about ` catchError ` in our [Errors and Retrying guide](/errors-retrying).
440
441
441
442
<Info>Uncaught errors will throw a special internal error of the type ` HANDLE_ERROR_ERROR ` .</Info>
442
443
0 commit comments