DEV Community

Discussion on: Pro tip: using Promise.then for function composition

Collapse
 
bgadrian profile image
Adrian B.G.

I've done a couple of functions like this, but still I haven't solved the problems of

  • testing it
  • how do you find out where exactly crashed on production and with what input?
Collapse
 
shalvah profile image
Shalvah
  • Testing: I don't think this is particularly a problem. You test them the way you test regular functions. Write unit tests for the individual functions and write a test for the entire pipeline.
  • Error handling: You can intersperse a couple of .catch blocks in there to handle specific errors during execution. But the problem would be when you need to exit the chain if an error occurs midway through. In such a case, I don't recommend using this approach, as that would lead to a lot of crazyyyy code. For uncaught errors, the stack trace would typically contain the name of the function that failed.

I hope I've addressed your concerns. Did I miss something?