Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: introduce an error for drafts not found when published record exists #284

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions invenio_drafts_resources/resources/records/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import json

from flask_resources.errors import HTTPJSONException
from invenio_pidstore.errors import PIDDoesNotExistError


class RedirectException(HTTPJSONException):
Expand Down Expand Up @@ -42,3 +43,7 @@ def get_body(self, environ=None, scope=None):
"location": self.location,
}
return json.dumps(body)


class DraftNotCreatedError(PIDDoesNotExistError):
"""Draft is not created for published record error."""
3 changes: 2 additions & 1 deletion invenio_drafts_resources/services/records/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from sqlalchemy.orm.exc import NoResultFound
from werkzeug.local import LocalProxy

from ...resources.records.errors import DraftNotCreatedError
from .uow import ParentRecordCommitOp


Expand Down Expand Up @@ -205,7 +206,7 @@ def read_draft(self, identity, id_, expand=False):
# with object id exists for the published record, but object
# getter fails to get the draft object because only the record
# object exists).
raise PIDDoesNotExistError(self.draft_cls.pid.field._pid_type, id_)
raise DraftNotCreatedError(self.draft_cls.pid.field._pid_type, id_)

self.require_permission(identity, "read_draft", record=draft)

Expand Down
Loading