-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
f7aff4a
ad06c92
c88dc16
4316fc4
c6b4cf1
4d54a4c
55bc4e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 NotFoundError from '@/domain/entities/errors/NotFound'; | ||
import useHeader from './useHeader'; | ||
import { getTitle } from '@/infrastructure/utils/note'; | ||
|
||
|
@@ -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 NotFoundError) { | ||
void router.push(`/error/404?message=${error.message}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to specify error message directly, instead of using Other code looks good for me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have removed that custom message, now it will get message based on code , in this case it will be 'Page not found'(i18n), is it ok |
||
} else { | ||
void router.push('/error/500'); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import DomainError from './Base'; | ||
|
||
/** | ||
* Domain error thrown when unknown error occurs | ||
*/ | ||
export default class ApiError extends DomainError { | ||
/** | ||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think, that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, currently it is not needed, I had created the ApiError to consider it as default error, to check api error response is instance of ApiError or not, |
||
* Constructor for ApiError error | ||
* @param message - Error message | ||
* @param statusCode - Error status code | ||
*/ | ||
constructor(message: string, public statusCode: number) { | ||
super(message); | ||
this.name = 'ApiError'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see where
?message
is composed. And it's better to use a prop instead of adding a message to the URL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you want 'page not found' message right, so on error component it is getting that message from i18n based on error code, if you want custom message then we can pass it as query