From 1a3880eceea67baf4886337342f6f6ed453bb7c0 Mon Sep 17 00:00:00 2001
From: Sheng <webmaster0115@gmail.com>
Date: Sun, 26 Aug 2018 15:40:08 +0800
Subject: [PATCH] Raise InvalidException for empty required value

---
 tests/test_app.py | 8 ++++----
 webssh/handler.py | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/test_app.py b/tests/test_app.py
index f29340d..4ee2742 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -87,17 +87,17 @@ class TestApp(AsyncHTTPTestCase):
         body = 'hostname=&port=&username=&password'
         response = self.fetch('/', method='POST', body=body)
         self.assertEqual(response.code, 400)
-        self.assertIn(b'Missing argument hostname', response.body)
+        self.assertIn(b'Missing value hostname', response.body)
 
         body = 'hostname=127.0.0.1&port=&username=&password'
         response = self.fetch('/', method='POST', body=body)
         self.assertEqual(response.code, 400)
-        self.assertIn(b'Missing argument port', response.body)
+        self.assertIn(b'Missing value port', response.body)
 
         body = 'hostname=127.0.0.1&port=7000&username=&password'
         response = self.fetch('/', method='POST', body=body)
         self.assertEqual(response.code, 400)
-        self.assertIn(b'Missing argument username', response.body)
+        self.assertIn(b'Missing value username', response.body)
 
     def test_app_with_invalid_form_for_invalid_value(self):
         body = 'hostname=127.0.0&port=22&username=&password'
@@ -234,7 +234,7 @@ class TestApp(AsyncHTTPTestCase):
         ws = yield tornado.websocket.websocket_connect(ws_url)
         msg = yield ws.read_message()
         self.assertIsNone(msg)
-        self.assertIn('Missing argument id', ws.close_reason)
+        self.assertIn('Missing value id', ws.close_reason)
 
     @tornado.testing.gen_test
     def test_app_with_correct_credentials_but_wrong_id(self):
diff --git a/webssh/handler.py b/webssh/handler.py
index 98868d4..c982ce5 100644
--- a/webssh/handler.py
+++ b/webssh/handler.py
@@ -55,7 +55,7 @@ class MixinHandler(object):
     def get_value(self, name):
         value = self.get_argument(name)
         if not value:
-            raise tornado.web.MissingArgumentError(name)
+            raise InvalidException('Missing value {}'.format(name))
         return value
 
     def get_real_client_addr(self):
@@ -261,8 +261,8 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
         logging.info('Connected from {}:{}'.format(*self.src_addr))
         try:
             worker_id = self.get_value('id')
-        except tornado.web.MissingArgumentError as exc:
-            self.close(reason=exc.log_message)
+        except (tornado.web.MissingArgumentError, InvalidException) as exc:
+            self.close(reason=str(exc))
             raise
         else:
             worker = workers.get(worker_id)