Add/Fix all error handling mechanism on REST API

 * Refactor error handling
 * add tests for correct error codes

Closes bug: #1320136
Co-Authored-By: Angus Salkeld <angus.salkeld@rackspace.com>
Change-Id: Ia33e19cab4879164acb7c8268c9c657f4196df45