Handle IntegrityError when creating new alias
This commit is contained in:
parent
bdec727cd1
commit
9f50ab4cce
|
@ -3,6 +3,7 @@ from dataclasses import dataclass
|
||||||
from flask import render_template, redirect, url_for, flash, request
|
from flask import render_template, redirect, url_for, flash, request
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from itsdangerous import TimestampSigner, SignatureExpired
|
from itsdangerous import TimestampSigner, SignatureExpired
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from app.config import (
|
from app.config import (
|
||||||
DISABLE_ALIAS_SUFFIX,
|
DISABLE_ALIAS_SUFFIX,
|
||||||
|
@ -203,6 +204,7 @@ def custom_alias():
|
||||||
if domain:
|
if domain:
|
||||||
custom_domain_id = domain.id
|
custom_domain_id = domain.id
|
||||||
|
|
||||||
|
try:
|
||||||
alias = Alias.create(
|
alias = Alias.create(
|
||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
email=full_alias,
|
email=full_alias,
|
||||||
|
@ -211,6 +213,11 @@ def custom_alias():
|
||||||
custom_domain_id=custom_domain_id,
|
custom_domain_id=custom_domain_id,
|
||||||
)
|
)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
except IntegrityError:
|
||||||
|
LOG.warning("Alias %s already exists", full_alias)
|
||||||
|
db.session.rollback()
|
||||||
|
flash("Unknown error, please retry", "error")
|
||||||
|
return redirect(url_for("dashboard.custom_alias"))
|
||||||
|
|
||||||
for i in range(1, len(mailboxes)):
|
for i in range(1, len(mailboxes)):
|
||||||
AliasMailbox.create(
|
AliasMailbox.create(
|
||||||
|
|
Loading…
Reference in a new issue