소스 검색

More/Better error messages

Eren Yilmaz 5 년 전
부모
커밋
871dbf9ac7
2개의 변경된 파일9개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 2
      run_client.py
  2. 5 1
      server_controller.py

+ 4 - 2
run_client.py

@@ -92,8 +92,10 @@ def one_command():
                 method_to_call(*cmd[1:])
             except TypeError:
                 print('Invalid command syntax.')
-            except Exception:
-                print('An error occurred while executing a command.')
+            except ConnectionError:
+                print('There has been a problem connecting when to the server.')
+            except Exception as _:
+                print('An unknown error occurred while executing a command.')
 
 
 def exit_client():

+ 5 - 1
server_controller.py

@@ -1,5 +1,6 @@
 import json
 from datetime import timedelta, datetime
+from math import ceil, floor
 
 from bottle import request, response
 from passlib.hash import sha256_crypt
@@ -88,6 +89,9 @@ def order():
 
     buy = request.json['buy']
     sell = not buy
+    if not isinstance(buy, bool):
+        return bad_request('`buy` must be a boolean')
+
     session_id = request.json['session_id']
     amount = request.json['amount']
     try:
@@ -115,7 +119,7 @@ def order():
         else:
             limit = float(request.json['limit'])
     except ValueError:  # for example when float fails
-        limit = None
+        return bad_request('Invalid limit.')
     except KeyError:  # for example when limit was not specified
         limit = None