ID-164 fixes based on code review
- use nested if-then-else to handle errors instead of throwing exceptions
- use 400 instead of 500 status for non-server errors
- move email parameters in application config