Fix behavior on invalid input file

Respond with 500 Internal Server Error instead of throwing an error
Add tests