-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
50 lines (41 loc) · 1.1 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import flask
from functools import wraps
from app import db
class ScaleAVCutterError(Exception):
def __init__(self, msg, *args):
super(ScaleAVCutterError, self).__init__(*args)
self.msg = msg
def __repr__(self):
return self.msg
def catch_error(inner):
@wraps(inner)
def wrapper(*args, **kwargs):
try:
return inner(*args, **kwargs)
except Exception as e:
return {'error': repr(e)}
return wrapper
def commit_db(inner):
@wraps(inner)
def wrapper(*args, **kwargs):
try:
res = inner(*args, **kwargs)
db.session.commit()
return res
except Exception as e:
db.session.rollback()
raise e
return wrapper
def error(msg):
raise ScaleAVCutterError(msg)
def access_error():
error('Insufficient access level')
def input_error():
error('Input error')
def expect(request, arg, optional=False):
if arg not in request.values:
if not optional:
input_error()
else:
return None
return request.values[arg]