mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-25 03:51:44 -05:00
Reraise integrity errors on org name unique contraints as 400
- currently being raised as 500s, but should really be 400s as the request data has the duplicate name
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from flask import Blueprint, current_app, jsonify, request
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.dao.organisation_dao import (
|
||||
dao_create_organisation,
|
||||
@@ -22,6 +23,21 @@ organisation_blueprint = Blueprint('organisation', __name__)
|
||||
register_errors(organisation_blueprint)
|
||||
|
||||
|
||||
@organisation_blueprint.errorhandler(IntegrityError)
|
||||
def handle_integrity_error(exc):
|
||||
"""
|
||||
Handle integrity errors caused by the unique contraint on ix_organisation_name
|
||||
"""
|
||||
if 'ix_organisation_name' in str(exc):
|
||||
current_app.logger.exception('Unique constraint ix_organisation_name triggered')
|
||||
return jsonify(
|
||||
result='error',
|
||||
message='Organisation name already exists'
|
||||
), 400
|
||||
|
||||
raise
|
||||
|
||||
|
||||
@organisation_blueprint.route('', methods=['GET'])
|
||||
def get_organisations():
|
||||
organisations = [
|
||||
|
||||
Reference in New Issue
Block a user