Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Redirect to 404 Page When Note is Not Found #277

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/application/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"marketplace": "Marketplace",
"addTool": "Add tool",
"notFound": "Not found",
"unexpectedError": "Unexpected error",
"joinTeam": "Join",
"authorization": "Authorize",
"history": "History",
Expand Down
12 changes: 12 additions & 0 deletions src/application/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ const routes: RouteRecordRaw[] = [
code: 404,
},
},
{
path: '/500',
component: ErrorPage,
meta: {
layout: 'fullpage',
pageTitleI18n: 'pages.unexpectedError',
discardTabOnLeave: true,
},
props: {
code: 500,
},
},
];

export default routes;
21 changes: 15 additions & 6 deletions src/application/services/useNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { NoteTool } from '@/domain/entities/Note';
import { useRouter, useRoute } from 'vue-router';
import type { NoteDraft } from '@/domain/entities/NoteDraft';
import type EditorTool from '@/domain/entities/EditorTool';
import ApiError from '@/domain/entities/errors/ApiError';
import useHeader from './useHeader';
import { getTitle } from '@/infrastructure/utils/note';

Expand Down Expand Up @@ -166,12 +167,20 @@ export default function (options: UseNoteComposableOptions): UseNoteComposableSt
/**
* @todo try-catch domain errors
*/
const response = await noteService.getNoteById(id);

note.value = response.note;
canEdit.value = response.accessRights.canEdit;
noteTools.value = response.tools;
parentNote.value = response.parentNote;
try {
const response = await noteService.getNoteById(id);

note.value = response.note;
canEdit.value = response.accessRights.canEdit;
noteTools.value = response.tools;
parentNote.value = response.parentNote;
} catch (error) {
if (error instanceof ApiError) {
void router.push('/500');
} else {
void router.push('/400');
}
e11sy marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/domain/entities/errors/ApiError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import DomainError from './Base';

/**
* Domain error thrown when some resource is not found
*/
e11sy marked this conversation as resolved.
Show resolved Hide resolved
export default class ApiError extends DomainError {
/**
* Constructor for ApiError error
* @param message - Error message
* @param statusCode - Error status code
*/
constructor(message: string, public statusCode: number) {
super(message);
this.name = 'ApiError';
}
}
3 changes: 2 additions & 1 deletion src/infrastructure/transport/notes-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AuthorizableTransport from '@/infrastructure/transport/authorizable.trans
import type JSONValue from '../types/JSONValue';
import UnauthorizedError from '@/domain/entities/errors/Unauthorized';
import NotFoundError from '@/domain/entities/errors/NotFound';
import ApiError from '@/domain/entities/errors/ApiError';
import type { FilesDto } from '../types/FileDto';

/**
Expand Down Expand Up @@ -53,7 +54,7 @@ export default class NotesApiTransport extends AuthorizableTransport {
case 404:
return new NotFoundError(errorText);
default:
return new Error(errorText);
return new ApiError(errorText, status);
}
},
});
Expand Down
Loading