What are the cons and pros of implementing a promise function/method in the following way? -
Return a promise only if all input parameters pass validation. Otherwise, throw TypeError
.
I used both of the following approaches in the past...
- Simply throwing an error:
throw new TypeError('Argument "bla-bla" is invalid...')
- Returning a rejection:
return Promise.reject(new TypeError('Argument "bla-bla" is invalid...'))
Now I am refactoring a library for that, to make it more consistent, and want to know the good/bad sides of either approaches first.
Aucun commentaire:
Enregistrer un commentaire