@@ -4,10 +4,14 @@ import cache from '@/utils/cache';
44import { parseRelativeDate } from '@/utils/parse-date' ;
55import { load } from 'cheerio' ;
66
7- async function getPageWithRealBrowser ( url : string , selector : string ) : Promise < string > {
8- const res = await fetch ( `${ config . puppeteerRealBrowserService } ?url=${ encodeURIComponent ( url ) } &selector=${ encodeURIComponent ( selector ) } ` ) ;
9- const json = await res . json ( ) ;
10- return ( json . data ?. at ( 0 ) || '' ) as string ;
7+ async function getPageWithRealBrowser ( url : string , selector : string ) {
8+ try {
9+ const res = await fetch ( `${ config . puppeteerRealBrowserService } ?url=${ encodeURIComponent ( url ) } &selector=${ encodeURIComponent ( selector ) } ` ) ;
10+ const json = await res . json ( ) ;
11+ return ( json . data ?. at ( 0 ) || '' ) as string ;
12+ } catch {
13+ return '' ;
14+ }
1115}
1216
1317export const route : Route = {
@@ -44,7 +48,7 @@ export const route: Route = {
4448
4549async function handler ( ctx ) {
4650 if ( ! config . puppeteerRealBrowserService ) {
47- throw new Error ( 'PUPPETEER_REAL_BROWSER_SERVICE or CHROMIUM_EXECUTABLE_PATH is required to use this route.' ) ;
51+ throw new Error ( 'PUPPETEER_REAL_BROWSER_SERVICE is required to use this route.' ) ;
4852 }
4953
5054 // NOTE: 'picnob' is still available, but all requests to 'picnob' will be redirected to 'pixnoy' eventually
@@ -54,6 +58,9 @@ async function handler(ctx) {
5458 const profileUrl = `${ baseUrl } /profile/${ id } /${ type === 'tagged' ? 'tagged/' : '' } ` ;
5559
5660 const html = await getPageWithRealBrowser ( profileUrl , '.post_box' ) ;
61+ if ( ! html ) {
62+ throw new Error ( 'Failed to fetch user profile page. User may not exist or there are no posts available.' ) ;
63+ }
5764
5865 const $ = load ( html ) ;
5966
0 commit comments