Fix documents UI
- Fix redirection after document deletion in detail page - Fix refetch after publication - Return proper error when trying to update a published document Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -46,6 +46,9 @@ type (
|
||||
ErrDocumentVersionNoChanges struct {
|
||||
}
|
||||
|
||||
ErrDocumentVersionNotDraft struct {
|
||||
}
|
||||
|
||||
ErrDocumentVersionSignatureAlreadySigned struct {
|
||||
}
|
||||
|
||||
@@ -154,6 +157,10 @@ func (e ErrDocumentVersionNoChanges) Error() string {
|
||||
return "no changes detected"
|
||||
}
|
||||
|
||||
func (e ErrDocumentVersionNotDraft) Error() string {
|
||||
return "cannot update a published document version"
|
||||
}
|
||||
|
||||
func (e ErrDocumentVersionSignatureAlreadySigned) Error() string {
|
||||
return "document version signature already signed"
|
||||
}
|
||||
@@ -781,7 +788,7 @@ func (s *DocumentService) UpdateVersion(
|
||||
}
|
||||
|
||||
if documentVersion.Status != coredata.DocumentStatusDraft {
|
||||
return fmt.Errorf("cannot update published version")
|
||||
return &ErrDocumentVersionNotDraft{}
|
||||
}
|
||||
|
||||
documentVersion.Title = document.Title
|
||||
|
||||
@@ -4429,8 +4429,16 @@ func (r *mutationResolver) UpdateDocumentVersion(ctx context.Context, input type
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
// TODO no panic use gqlutils.InternalError
|
||||
panic(fmt.Errorf("cannot update document version: %w", err))
|
||||
if errors.Is(err, coredata.ErrResourceNotFound) {
|
||||
return nil, gqlutils.NotFound(ctx, err)
|
||||
}
|
||||
|
||||
if errNotDraft, ok := errors.AsType[*probo.ErrDocumentVersionNotDraft](err); ok {
|
||||
return nil, gqlutils.Conflict(ctx, errNotDraft)
|
||||
}
|
||||
|
||||
r.logger.ErrorCtx(ctx, "cannot update document version", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
|
||||
return &types.UpdateDocumentVersionPayload{
|
||||
|
||||
Reference in New Issue
Block a user