Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Return 409 on DB conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Navarro Bosch committed Jan 21, 2017
1 parent fb631a7 commit 99b6887
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/plone.server/plone/server/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from zope.security.interfaces import IPermission
from zope.security.interfaces import Unauthorized
from zope.security.proxy import ProxyFactory
from ZODB.POSException import ConflictError

import aiohttp
import asyncio
Expand Down Expand Up @@ -158,7 +159,7 @@ def generate_unauthorized_response(e, request):
return UnauthorizedResponse(message)


def generate_error_response(e, request, error):
def generate_error_response(e, request, error, status=400):
# We may need to check the roles of the users to show the real error
eid = uuid.uuid4().hex
message = _('Error on execution of view') + ' ' + eid
Expand All @@ -168,7 +169,8 @@ def generate_error_response(e, request, error):

return ErrorResponse(
error,
message
message,
status
)


Expand Down Expand Up @@ -205,6 +207,9 @@ async def handler(self, request):
except Unauthorized as e:
await abort(txn, request)
view_result = generate_unauthorized_response(e, request)
except ConflictError as e:
view_result = generate_error_response(
e, request, 'ServiceError', 409)
except Exception as e:
await abort(txn, request)
view_result = generate_error_response(
Expand Down

0 comments on commit 99b6887

Please sign in to comment.