Set correct HTTP status code on error

closes #1055
Merge pull request #1152 from jgillich/status-code

Set correct HTTP status code on error