inngest / inngest-js

The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript
https://www.inngest.com/
GNU General Public License v3.0
414 stars 41 forks source link

[FEATURE]Adding type for InngestStepError to handle the onfailure logic based on failed step #397

Open anasabdullahysfzai opened 10 months ago

anasabdullahysfzai commented 10 months ago

So i have been working on a multistep function where the onFailure logic was different based on the step that failed. I didnt find a way to handle this in inngest

As a workaround , i had to pass the step name property within the error object like below

throw { step: "scrape-website", error: error_instance }

I think we can handle this issue on inngest level by introducing a new type called InngestStepError which includes the step name (name of failed step) and the original error that was thrown while running the step. So we can throw error like this

throw new InngestStepError({step: "scrape-website"},error)

And handle the onFailure based on step

` onFailure: async ({ error, event }) => {

switch(error.step) { case "scrape-website": // Do Something break; case "step-2": // Do Something break; }

} `

anasabdullahysfzai commented 10 months ago

@jpwilliams can i work on this?