I am building an API in expressjs and, currently, mongo/mongoose. I currently have some model methods that return true or false, some that return a value or false, and some that return a value or throw an error.
This is making my handlers a bit cumbersome / complex so before the project gets any larger I'd like to standardize on one way of handling errors at the model level. I can think of two ways to accomplish this...
Strategy 1. Make all model methods either return a value or throw an error. The handler would wrap the call in a try/catch. Any custom errors I generated would have unique codes to differentiate them to the code in the handler's catch block.
Strategy 2: Make all model methods return an Object and do all the trying and catching within the model methods. The returned Object would always have either a result property or an error and errCode property if there was an error so my handler could check that and respond appropriately.
I'm slightly leaning towards #1 right now but I thought I'd ask here to see if anyone can suggest some good reasons to avoid or embrace either approach - or indeed suggest a third way. Thanks for reading!