API: return 400 and better message for missing entity

Fix issue #380
Merge pull request #394 from flodolo/issue380

API: return 400 and better message for missing entity