Better error handling and code simplified

Looks like this is changing API behavior by returning http status 500. Have you tested that this works with the existing lamassu-machine code?