Added closure around API handlers to handle errors.