fix: Handle doc not found / no permission

closes #1021
This commit is contained in:
Tom Moor
2019-08-21 22:11:54 -07:00
parent e2b28dfeb7
commit 54565fff74
2 changed files with 24 additions and 30 deletions

View File

@@ -31,7 +31,6 @@ import CenteredContent from 'components/CenteredContent';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
import Notice from 'shared/components/Notice'; import Notice from 'shared/components/Notice';
import Time from 'shared/components/Time'; import Time from 'shared/components/Time';
import Search from 'scenes/Search';
import Error404 from 'scenes/Error404'; import Error404 from 'scenes/Error404';
import ErrorOffline from 'scenes/ErrorOffline'; import ErrorOffline from 'scenes/ErrorOffline';
@@ -82,7 +81,7 @@ class DocumentScene extends React.Component<Props> {
@observable isPublishing: boolean = false; @observable isPublishing: boolean = false;
@observable isDirty: boolean = false; @observable isDirty: boolean = false;
@observable isEmpty: boolean = true; @observable isEmpty: boolean = true;
@observable notFound: boolean = false; @observable error: ?Error;
@observable moveModalOpen: boolean = false; @observable moveModalOpen: boolean = false;
constructor(props) { constructor(props) {
@@ -154,18 +153,23 @@ class DocumentScene extends React.Component<Props> {
} else { } else {
const { shareId, revisionId } = props.match.params; const { shareId, revisionId } = props.match.params;
this.document = await props.documents.fetch( try {
props.match.params.documentSlug, this.document = await props.documents.fetch(
{ shareId }
);
if (revisionId) {
this.revision = await props.revisions.fetch(
props.match.params.documentSlug, 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; this.isDirty = false;
@@ -197,9 +201,6 @@ class DocumentScene extends React.Component<Props> {
} }
} }
} }
} else {
// Render 404 with search
this.notFound = true;
} }
} }
}; };
@@ -315,16 +316,8 @@ class DocumentScene extends React.Component<Props> {
const revision = this.revision; const revision = this.revision;
const isShare = match.params.shareId; const isShare = match.params.shareId;
if (this.notFound) { if (this.error) {
return navigator.onLine ? ( return navigator.onLine ? <Error404 /> : <ErrorOffline />;
isShare ? (
<Error404 />
) : (
<Search notFound />
)
) : (
<ErrorOffline />
);
} }
if (!document || !Editor) { if (!document || !Editor) {

View File

@@ -8,11 +8,12 @@ const Error404 = () => {
return ( return (
<CenteredContent> <CenteredContent>
<PageTitle title="Not Found" /> <PageTitle title="Not Found" />
<h1>Not Found</h1> <h1>Not found</h1>
<Empty>We were unable to find the page youre looking for.</Empty> <Empty>
<p> We were unable to find the page youre looking for. Go to the&nbsp;<a href="/">
Go to <a href="/">homepage</a>. homepage
</p> </a>?
</Empty>
</CenteredContent> </CenteredContent>
); );
}; };