| 1 | const 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 | |
| 21 | export default fetchFileTextContent |