MCPcopy Create free account
hub / github.com/21st-dev/21st-sdk / fetchFileTextContent

Function fetchFileTextContent

apps/agents-web/lib/utils/fetchFileTextContent.ts:1–19  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

1const fetchFileTextContent = async (url: string) => {
2 const filename = url.split("/").slice(-1)[0]
3 try {
4 const response = await fetch(url)
5 if (!response.ok) {
6 console.error(`Error response in fetching file ${filename}`, response)
7 throw new Error(
8 `Error response in fetching file ${filename}: ${response.statusText}`,
9 )
10 }
11 return { data: await response.text(), error: null }
12 } catch (err) {
13 console.error(`Failed to fetch file ${filename}`, err)
14 return {
15 error: new Error(`Failed to fetch file ${filename}: ${err}`),
16 data: null,
17 }
18 }
19}
20
21export default fetchFileTextContent

Callers 1

POSTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected