Skip to content

Commit

Permalink
errors: introduce an error for drafts not found when publish record e…
Browse files Browse the repository at this point in the history
  • Loading branch information
anikachurilova authored and kpsherva committed Jul 4, 2024
1 parent 4489a79 commit 4254fde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit 4254fde

Please sign in to comment.