Boundary Event Error handler

I’m trying to create a flow similar to the below image however, the problem is whenever i try to raise an error through Python Script (“For Service Task Reserve Order Items”)rather then completing the it fails the job
The python code I’m using is as below

from pyzeebe import ZeebeTaskRouter
from pyzeebe import ZeebeWorker, create_insecure_channel,Job
import asyncio
import random
import nest_asyncio
nest_asyncio.apply()


async def my_exception_handler(exception: Exception, job: Job) -> None:
	print(exception)
	await job.set_failure_status(message=str(exception))

async def main():
	worker = ZeebeWorker(channel)
	router = ZeebeTaskRouter()
  
  
	@router.task(task_type="CheckWhetherItemExist")
	def CheckWhetherItemExist(product: str,productQuantity:int, exception_handler=my_exception_handler):
		print(f"product:-{product}, and productQuantity:-{productQuantity}")
		raise Exception("itemsOutOfStock")
		return {}
  
	worker.include_router(router)
	await worker.work()
  
asyncio.run(main())
print("done")

Any Help or guidance will be a great help.

Actually i was able to resolve the issue myself though the mistake was very small i had to include the error handling at the decorator level but had given it as a parameter to the function thats why the task was failing . below is the solution that worked

from pyzeebe import ZeebeTaskRouter
from pyzeebe import ZeebeWorker, create_insecure_channel,Job
import asyncio
import random
import nest_asyncio
nest_asyncio.apply()




async def main():
	worker = ZeebeWorker(channel)
	router = ZeebeTaskRouter()

	async def my_exception_handler(exception: Exception, job: Job) -> None:
		print(exception)
		print("yahoo")
		await job.set_error_status(message= 'itemsOutOfStock', error_code='itemsOutOfStock') 
		
	@router.task(task_type="CheckWhetherItemExist", exception_handler=my_exception_handler)
	def CheckWhetherItemExist(product: str,productQuantity:int):
		print(f"product:-{product}, and productQuantity:-{productQuantity}")
		raise Exception()
		return {}
	
	worker.include_router(router)
	await worker.work()

asyncio.run(main())
print("done")
1 Like

@Sachin_Rajput thanks for sharing!