Revamp gatekeeper error handling.

Errors generated by the gatekeeper are now returned in the format of the
request (so JSON requests will return JSON errors, XML requests will
return XML errors, etc).

Additionally, the error responses are now handled by templates for each
format, so different APIs can define custom error responses in their
settings.