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 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<Props> {
@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<Props> {
} 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<Props> {
}
}
}
} else {
// Render 404 with search
this.notFound = true;
}
}
};
@ -315,16 +316,8 @@ class DocumentScene extends React.Component<Props> {
const revision = this.revision;
const isShare = match.params.shareId;
if (this.notFound) {
return navigator.onLine ? (
isShare ? (
<Error404 />
) : (
<Search notFound />
)
) : (
<ErrorOffline />
);
if (this.error) {
return navigator.onLine ? <Error404 /> : <ErrorOffline />;
}
if (!document || !Editor) {

View File

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