From 54565fff74ef6bcf3e9f8aad9a4204bd4e3d0dee Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 21 Aug 2019 22:11:54 -0700 Subject: [PATCH] fix: Handle doc not found / no permission closes #1021 --- app/scenes/Document/Document.js | 43 ++++++++++++++------------------- app/scenes/Error404.js | 11 +++++---- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/scenes/Document/Document.js b/app/scenes/Document/Document.js index fbc62882d..a9fdcb54e 100644 --- a/app/scenes/Document/Document.js +++ b/app/scenes/Document/Document.js @@ -31,7 +31,6 @@ import CenteredContent from 'components/CenteredContent'; import PageTitle from 'components/PageTitle'; import Notice from 'shared/components/Notice'; import Time from 'shared/components/Time'; -import Search from 'scenes/Search'; import Error404 from 'scenes/Error404'; import ErrorOffline from 'scenes/ErrorOffline'; @@ -82,7 +81,7 @@ class DocumentScene extends React.Component { @observable isPublishing: boolean = false; @observable isDirty: boolean = false; @observable isEmpty: boolean = true; - @observable notFound: boolean = false; + @observable error: ?Error; @observable moveModalOpen: boolean = false; constructor(props) { @@ -154,18 +153,23 @@ class DocumentScene extends React.Component { } else { const { shareId, revisionId } = props.match.params; - this.document = await props.documents.fetch( - props.match.params.documentSlug, - { shareId } - ); - - if (revisionId) { - this.revision = await props.revisions.fetch( + try { + this.document = await props.documents.fetch( props.match.params.documentSlug, - { revisionId } + { shareId } ); - } else { - this.revision = undefined; + + if (revisionId) { + this.revision = await props.revisions.fetch( + props.match.params.documentSlug, + { revisionId } + ); + } else { + this.revision = undefined; + } + } catch (err) { + this.error = err; + return; } this.isDirty = false; @@ -197,9 +201,6 @@ class DocumentScene extends React.Component { } } } - } else { - // Render 404 with search - this.notFound = true; } } }; @@ -315,16 +316,8 @@ class DocumentScene extends React.Component { const revision = this.revision; const isShare = match.params.shareId; - if (this.notFound) { - return navigator.onLine ? ( - isShare ? ( - - ) : ( - - ) - ) : ( - - ); + if (this.error) { + return navigator.onLine ? : ; } if (!document || !Editor) { diff --git a/app/scenes/Error404.js b/app/scenes/Error404.js index ebb858ca0..6d8e9a30c 100644 --- a/app/scenes/Error404.js +++ b/app/scenes/Error404.js @@ -8,11 +8,12 @@ const Error404 = () => { return ( -

Not Found

- We were unable to find the page you’re looking for. -

- Go to homepage. -

+

Not found

+ + We were unable to find the page you’re looking for. Go to the  + homepage + ? +
); };