Skip to content

Commit cdb891b

Browse files
committed
fix(ui): handle 404 for non-existing profiles
1 parent c4ab87d commit cdb891b

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

app/pages/profile/[handle]/index.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,27 @@ import { updateProfile as updateProfileUtil } from '~/utils/atproto/profile'
44
const route = useRoute('profile-handle')
55
const handle = computed(() => route.params.handle)
66
7-
const { data: profile } = useFetch<NPMXProfile>(() => `/api/social/profile/${handle.value}`, {
7+
const {
8+
data: profile,
9+
status: profileStatus,
10+
error: profileError,
11+
} = await useFetch<NPMXProfile>(() => `/api/social/profile/${handle.value}`, {
812
default: () => ({ displayName: handle.value, description: '', website: '' }),
9-
server: false,
1013
})
1114
15+
if (
16+
profileStatus.value === 'error' &&
17+
profileError.value?.statusCode &&
18+
profileError.value.statusCode >= 400 &&
19+
profileError.value.statusCode < 500
20+
) {
21+
throw createError({
22+
statusCode: 404,
23+
statusMessage: $t('profile.not_found'),
24+
message: $t('profile.not_found_message', { handle: handle.value }),
25+
})
26+
}
27+
1228
const { user } = useAtproto()
1329
const isEditing = ref(false)
1430
const displayNameInput = ref()

i18n/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@
154154
"website_placeholder": "https://example.com",
155155
"likes": "Likes",
156156
"seo_title": "{handle} - npmx",
157-
"seo_description": "npmx profile by {handle}"
157+
"seo_description": "npmx profile by {handle}",
158+
"not_found": "Profile Not Found",
159+
"not_found_message": "The profile for {handle} could not be found."
158160
},
159161
"package": {
160162
"not_found": "Package Not Found",

i18n/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@
468468
},
469469
"seo_description": {
470470
"type": "string"
471+
},
472+
"not_found": {
473+
"type": "string"
474+
},
475+
"not_found_message": {
476+
"type": "string"
471477
}
472478
},
473479
"additionalProperties": false

lunaria/files/en-GB.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@
153153
"website_placeholder": "https://example.com",
154154
"likes": "Likes",
155155
"seo_title": "{handle} - npmx",
156-
"seo_description": "npmx profile by {handle}"
156+
"seo_description": "npmx profile by {handle}",
157+
"not_found": "Profile Not Found",
158+
"not_found_message": "The profile for {handle} could not be found."
157159
},
158160
"package": {
159161
"not_found": "Package Not Found",

lunaria/files/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@
153153
"website_placeholder": "https://example.com",
154154
"likes": "Likes",
155155
"seo_title": "{handle} - npmx",
156-
"seo_description": "npmx profile by {handle}"
156+
"seo_description": "npmx profile by {handle}",
157+
"not_found": "Profile Not Found",
158+
"not_found_message": "The profile for {handle} could not be found."
157159
},
158160
"package": {
159161
"not_found": "Package Not Found",

0 commit comments

Comments
 (0)