Issuing status code 500 on error

closes #356