Rewrite abort messages.
This commit is contained in:
parent
de5e0482cd
commit
af05a3d6ba
@ -149,10 +149,7 @@ class AccountListResource(Resource):
|
|||||||
|
|
||||||
# A new account MUST NOT have an id;
|
# A new account MUST NOT have an id;
|
||||||
if 'id' in data and data['id']:
|
if 'id' in data and data['id']:
|
||||||
ns.abort(
|
ns.abort(406, 'Id must not be provided on creation.')
|
||||||
406,
|
|
||||||
error_message='Id must not be provided on creation.'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Instantiate account with data.
|
# Instantiate account with data.
|
||||||
account = Account(**data)
|
account = Account(**data)
|
||||||
@ -189,10 +186,7 @@ class AccountResource(Resource):
|
|||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# Note: if we don't pass the code, the result is seen as a tuple and
|
# Note: if we don't pass the code, the result is seen as a tuple and
|
||||||
# causes error on marshalling.
|
# causes error on marshalling.
|
||||||
@ -210,19 +204,13 @@ class AccountResource(Resource):
|
|||||||
|
|
||||||
# Check ID consistency.
|
# Check ID consistency.
|
||||||
if 'id' in data and data['id'] and data['id'] != account_id:
|
if 'id' in data and data['id'] and data['id'] != account_id:
|
||||||
ns.abort(
|
ns.abort(406, 'Id must not be provided or changed on update.')
|
||||||
406,
|
|
||||||
error_message='Id must not be provided or changed on update.'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Need to get the object to update it.
|
# Need to get the object to update it.
|
||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# SQLAlchemy objects ignore __dict__.update() with merge.
|
# SQLAlchemy objects ignore __dict__.update() with merge.
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
@ -243,10 +231,7 @@ class AccountResource(Resource):
|
|||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
db.session.delete(account) # pylint: disable=no-member
|
db.session.delete(account) # pylint: disable=no-member
|
||||||
|
|
||||||
@ -275,10 +260,7 @@ class SoldsResource(Resource):
|
|||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# Note: if we don't pass the code, the result is seen as a tuple and
|
# Note: if we don't pass the code, the result is seen as a tuple and
|
||||||
# causes error on marshalling.
|
# causes error on marshalling.
|
||||||
@ -308,10 +290,7 @@ class BalanceResource(Resource):
|
|||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
data = range_parser.parse_args()
|
data = range_parser.parse_args()
|
||||||
|
|
||||||
|
@ -129,17 +129,11 @@ class OperationListResource(Resource):
|
|||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# A new operation MUST NOT have an id;
|
# A new operation MUST NOT have an id;
|
||||||
if 'id' in data and data['id']:
|
if 'id' in data and data['id']:
|
||||||
ns.abort(
|
ns.abort(406, 'Id must not be provided on creation.')
|
||||||
406,
|
|
||||||
error_message='Id must not be provided on creation.'
|
|
||||||
)
|
|
||||||
|
|
||||||
operation = Operation(**data)
|
operation = Operation(**data)
|
||||||
|
|
||||||
@ -172,10 +166,7 @@ class OperationResource(Resource):
|
|||||||
# pylint: enable=no-member
|
# pylint: enable=no-member
|
||||||
|
|
||||||
if not operation:
|
if not operation:
|
||||||
ns.abort(
|
ns.abort(404, 'Operation with id %d not found.' % operation_id)
|
||||||
404,
|
|
||||||
error_message='Operation with id %d not found.' % operation_id
|
|
||||||
)
|
|
||||||
|
|
||||||
return operation, 200
|
return operation, 200
|
||||||
|
|
||||||
@ -191,20 +182,14 @@ class OperationResource(Resource):
|
|||||||
|
|
||||||
# Check ID consistency.
|
# Check ID consistency.
|
||||||
if 'id' in data and data['id'] and data['id'] != operation_id:
|
if 'id' in data and data['id'] and data['id'] != operation_id:
|
||||||
ns.abort(
|
ns.abort(406, 'Id must not be provided or changed on update.')
|
||||||
406,
|
|
||||||
error_message='Id must not be provided or changed on update.'
|
|
||||||
)
|
|
||||||
|
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
operation = db.session.query(Operation).get(operation_id)
|
operation = db.session.query(Operation).get(operation_id)
|
||||||
# pylint: enable=no-member
|
# pylint: enable=no-member
|
||||||
|
|
||||||
if not operation:
|
if not operation:
|
||||||
ns.abort(
|
ns.abort(404, 'Operation with id %d not found.' % operation_id)
|
||||||
404,
|
|
||||||
error_message='Operation with id %d not found.' % operation_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# FIXME check account_id consistency.
|
# FIXME check account_id consistency.
|
||||||
|
|
||||||
@ -227,10 +212,7 @@ class OperationResource(Resource):
|
|||||||
# pylint: enable=no-member
|
# pylint: enable=no-member
|
||||||
|
|
||||||
if not operation:
|
if not operation:
|
||||||
ns.abort(
|
ns.abort(404, 'Operation with id %d not found.' % operation_id)
|
||||||
404,
|
|
||||||
error_message='Operation with id %d not found.' % operation_id
|
|
||||||
)
|
|
||||||
|
|
||||||
db.session.delete(operation) # pylint: disable=no-member
|
db.session.delete(operation) # pylint: disable=no-member
|
||||||
|
|
||||||
|
@ -103,17 +103,11 @@ class ScheduledOperationListResource(Resource):
|
|||||||
account = Account.query().get(account_id)
|
account = Account.query().get(account_id)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
ns.abort(
|
ns.abort(404, 'Account with id %d not found.' % account_id)
|
||||||
404,
|
|
||||||
error_message='Account with id %d not found.' % account_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# A new scheduled operation MUST NOT have an id;
|
# A new scheduled operation MUST NOT have an id;
|
||||||
if 'id' in data and data['id']:
|
if 'id' in data and data['id']:
|
||||||
ns.abort(
|
ns.abort(406, 'Id must not be provided on creation.')
|
||||||
406,
|
|
||||||
error_message='Id must not be provided on creation.'
|
|
||||||
)
|
|
||||||
|
|
||||||
scheduled_operation = ScheduledOperation(**data)
|
scheduled_operation = ScheduledOperation(**data)
|
||||||
|
|
||||||
@ -150,10 +144,7 @@ class ScheduledOperationResource(Resource):
|
|||||||
scheduled_operation = ScheduledOperation.query().get(so_id)
|
scheduled_operation = ScheduledOperation.query().get(so_id)
|
||||||
|
|
||||||
if not scheduled_operation:
|
if not scheduled_operation:
|
||||||
ns.abort(
|
ns.abort(404, 'Scheduled operation with id %d not found.' % so_id)
|
||||||
404,
|
|
||||||
error_message='Scheduled operation with id %d not found.' % so_id
|
|
||||||
)
|
|
||||||
|
|
||||||
return scheduled_operation, 200
|
return scheduled_operation, 200
|
||||||
|
|
||||||
@ -170,18 +161,12 @@ class ScheduledOperationResource(Resource):
|
|||||||
|
|
||||||
# Check ID consistency.
|
# Check ID consistency.
|
||||||
if 'id' in data and data['id'] and data['id'] != so_id:
|
if 'id' in data and data['id'] and data['id'] != so_id:
|
||||||
ns.abort(
|
ns.abort(406, 'Id must not be provided or changed on update.')
|
||||||
406,
|
|
||||||
error_message='Id must not be provided or changed on update.'
|
|
||||||
)
|
|
||||||
|
|
||||||
scheduled_operation = ScheduledOperation.query().get(so_id)
|
scheduled_operation = ScheduledOperation.query().get(so_id)
|
||||||
|
|
||||||
if not scheduled_operation:
|
if not scheduled_operation:
|
||||||
ns.abort(
|
ns.abort(404, 'Scheduled operation with id %d not found.' % so_id)
|
||||||
404,
|
|
||||||
error_message='Scheduled operation with id %d not found.' % so_id
|
|
||||||
)
|
|
||||||
|
|
||||||
# FIXME check account_id consistency.
|
# FIXME check account_id consistency.
|
||||||
|
|
||||||
@ -209,20 +194,15 @@ class ScheduledOperationResource(Resource):
|
|||||||
scheduled_operation = ScheduledOperation.query().get(so_id)
|
scheduled_operation = ScheduledOperation.query().get(so_id)
|
||||||
|
|
||||||
if not scheduled_operation:
|
if not scheduled_operation:
|
||||||
ns.abort(
|
ns.abort(404, 'Scheduled operation with id %d not found.' % so_id)
|
||||||
404,
|
|
||||||
error_message='Scheduled operation with id %d not found.' % so_id
|
|
||||||
)
|
|
||||||
|
|
||||||
operations = scheduled_operation.operations.filter(
|
operations = scheduled_operation.operations.filter(
|
||||||
Operation.confirmed == true()
|
Operation.confirmed == true()
|
||||||
).count()
|
).count()
|
||||||
|
|
||||||
if operations:
|
if operations:
|
||||||
ns.abort(
|
ns.abort(409, 'There are still confirmed operations '
|
||||||
409,
|
'associated to this scheduled operation.')
|
||||||
error_message='There are still confirmed operations \
|
|
||||||
associated to this scheduled operation.')
|
|
||||||
|
|
||||||
# Delete unconfirmed operations
|
# Delete unconfirmed operations
|
||||||
scheduled_operation.operations.delete()
|
scheduled_operation.operations.delete()
|
||||||
|
@ -72,7 +72,7 @@ class LoginResource(Resource):
|
|||||||
).one_or_none()
|
).one_or_none()
|
||||||
|
|
||||||
if not user or not user.verify_password(password):
|
if not user or not user.verify_password(password):
|
||||||
ns.abort(401, error_message="Bad user or password.")
|
ns.abort(401, "Bad user or password.")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'access_token': create_access_token(identity=user),
|
'access_token': create_access_token(identity=user),
|
||||||
|
Loading…
Reference in New Issue
Block a user