Browse Source

Allow errors to carry HTTP codes

Getty Ritter 4 years ago
parent
commit
69ac477359
2 changed files with 7 additions and 1 deletions
  1. 1 1
      lc/app.py
  2. 6 0
      lc/error.py

+ 1 - 1
lc/app.py

@@ -31,7 +31,7 @@ def handle_errors(func):
                        content=f"shit's fucked yo: {exn}",
                        user=None
                 ),
-                500,
+                e.http_code(),
             )
 
     __wrapped__.__name__ = func.__name__

+ 6 - 0
lc/error.py

@@ -5,6 +5,9 @@ class LCException(Exception):
     def to_json(self) -> dict:
         return {"error": str(self)}
 
+    def http_code(self) -> int:
+        return 500
+
 
 @dataclass
 class UserExists(LCException):
@@ -21,6 +24,9 @@ class NoSuchUser(LCException):
     def __str__(self):
         return f"No user named {self.name} exists."
 
+    def http_code(self) -> int:
+        return 404
+
 
 @dataclass
 class BadPassword(LCException):