Skip to content

Commit bdb93f7

Browse files
authored
Merge pull request #1821 from 0xi4o/bug/web-scrapper-ui
Fix: Error Handling in Web Scraper
2 parents 2d9bf58 + 07ce50c commit bdb93f7

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

packages/server/src/index.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -1245,18 +1245,22 @@ export class App {
12451245
// ----------------------------------------
12461246

12471247
this.app.get('/api/v1/fetch-links', async (req: Request, res: Response) => {
1248-
const url = decodeURIComponent(req.query.url as string)
1249-
const relativeLinksMethod = req.query.relativeLinksMethod as string
1250-
if (!relativeLinksMethod) {
1251-
return res.status(500).send('Please choose a Relative Links Method in Additional Parameters.')
1252-
}
1248+
try {
1249+
const url = decodeURIComponent(req.query.url as string)
1250+
const relativeLinksMethod = req.query.relativeLinksMethod as string
1251+
if (!relativeLinksMethod) {
1252+
return res.status(500).send('Please choose a Relative Links Method in Additional Parameters.')
1253+
}
12531254

1254-
const limit = parseInt(req.query.limit as string)
1255-
if (process.env.DEBUG === 'true') console.info(`Start ${relativeLinksMethod}`)
1256-
const links: string[] = relativeLinksMethod === 'webCrawl' ? await webCrawl(url, limit) : await xmlScrape(url, limit)
1257-
if (process.env.DEBUG === 'true') console.info(`Finish ${relativeLinksMethod}`)
1255+
const limit = parseInt(req.query.limit as string)
1256+
if (process.env.DEBUG === 'true') console.info(`Start ${relativeLinksMethod}`)
1257+
const links: string[] = relativeLinksMethod === 'webCrawl' ? await webCrawl(url, limit) : await xmlScrape(url, limit)
1258+
if (process.env.DEBUG === 'true') console.info(`Finish ${relativeLinksMethod}`)
12581259

1259-
res.json({ status: 'OK', links })
1260+
res.json({ status: 'OK', links })
1261+
} catch (e: any) {
1262+
return res.status(500).send('Could not fetch links from the URL.')
1263+
}
12601264
})
12611265

12621266
// ----------------------------------------

packages/ui/src/ui-component/dialog/ManageScrapedLinksDialog.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Stack,
1717
Typography
1818
} from '@mui/material'
19-
import { IconTrash, IconX } from '@tabler/icons'
19+
import { IconEraser, IconTrash, IconX } from '@tabler/icons'
2020
import PerfectScrollbar from 'react-perfect-scrollbar'
2121

2222
import { BackdropLoader } from 'ui-component/loading/BackdropLoader'
@@ -113,6 +113,10 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
113113
setSelectedLinks(links)
114114
}
115115

116+
const handleRemoveAllLinks = () => {
117+
setSelectedLinks([])
118+
}
119+
116120
const handleSaveLinks = () => {
117121
onSave(url, selectedLinks)
118122
}
@@ -145,6 +149,7 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
145149
/>
146150
</FormControl>
147151
<Button
152+
disabled={!url}
148153
sx={{ borderRadius: '12px', mt: 1, display: 'flex', flexShrink: 0 }}
149154
size='small'
150155
variant='contained'
@@ -154,7 +159,21 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
154159
</Button>
155160
</Stack>
156161
</Box>
157-
<Typography sx={{ mb: 2, fontWeight: 500 }}>Scraped Links</Typography>
162+
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 1.5 }}>
163+
<Typography sx={{ fontWeight: 500 }}>Scraped Links</Typography>
164+
{selectedLinks.length > 0 ? (
165+
<StyledButton
166+
sx={{ height: 'max-content', width: 'max-content' }}
167+
variant='outlined'
168+
color='error'
169+
title='Clear All Links'
170+
onClick={handleRemoveAllLinks}
171+
startIcon={<IconEraser />}
172+
>
173+
Clear All
174+
</StyledButton>
175+
) : null}
176+
</Box>
158177
<>
159178
{loading && <BackdropLoader open={loading} />}
160179
{selectedLinks.length > 0 ? (

0 commit comments

Comments
 (0)