Getting lvgmc csv files in frontend

This commit is contained in:
Guntis Smaukstelis
2025-03-10 16:56:24 +02:00
parent 9d6b86e218
commit 841b4b6ec9
6 changed files with 62 additions and 6 deletions
+26
View File
@@ -25,6 +25,32 @@ export const fetchJson = (url: string, options = {}) => {
})
}
export const fetchText = (url: string, options = {}) => {
return fetch(url, options).then(async response => {
let responseCode = ''
if (!response.ok) {
responseCode = `error ${response.status}`
}
let text = ''
let responseMessage = ''
try {
text = await response.text()
} catch (err) {
responseMessage = 'Invalid TEXT response'
}
if (responseCode) {
if (responseMessage) throw new Error(`${responseCode}: ${responseMessage}`)
else throw new Error(responseCode)
} else if (responseMessage) {
throw new Error(responseMessage)
}
return text
})
}
export const fetchBuffer = (url: string, options = {}) => {
return fetch(url, options).then(async response => {