Support for passing the state parameter back in the error response, if it was passed in
Pulled out the way that the error codes are generated into the JSON object generated from a static map, instead of an icky switch statement