Improved Gateway error handling

* General improvements to reduce the case where something bad happens
  and RDP hangs around forever without closing.
* Specific error code improvement for CAP related login rejection.
Merge pull request #1714 from dbungert/gateway

Improved Gateway error handling