mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
remove unused functions from FetchHelper
This commit is contained in:
parent
28ddcdaa3d
commit
4cfcd3c20d
@ -1,16 +1,5 @@
|
|||||||
import fetch from 'cross-fetch'
|
import fetch from 'cross-fetch'
|
||||||
import { DownloadResponse } from '../@types'
|
import { DownloadResponse } from '../@types'
|
||||||
import { LoggerInstance } from '.'
|
|
||||||
|
|
||||||
export async function fetchData(url: string, opts: RequestInit): Promise<Response> {
|
|
||||||
const result = await fetch(url, opts)
|
|
||||||
if (!result.ok) {
|
|
||||||
LoggerInstance.error(`Error requesting [${opts.method}] ${url}`)
|
|
||||||
LoggerInstance.error(`Response message: \n${await result.text()}`)
|
|
||||||
throw result
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function downloadFileBrowser(url: string): Promise<void> {
|
export async function downloadFileBrowser(url: string): Promise<void> {
|
||||||
const anchor = document.createElement('a')
|
const anchor = document.createElement('a')
|
||||||
@ -42,28 +31,3 @@ export async function downloadFile(
|
|||||||
|
|
||||||
return { data: await response.arrayBuffer(), filename }
|
return { data: await response.arrayBuffer(), filename }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function postWithHeaders(
|
|
||||||
url: string,
|
|
||||||
payload: BodyInit,
|
|
||||||
headers: any
|
|
||||||
): Promise<Response> {
|
|
||||||
if (payload != null) {
|
|
||||||
return fetch(url, {
|
|
||||||
method: 'POST',
|
|
||||||
body: payload,
|
|
||||||
headers
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return fetch(url, {
|
|
||||||
method: 'POST'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function postData(url: string, payload: BodyInit): Promise<Response> {
|
|
||||||
const headers = {
|
|
||||||
'Content-type': 'application/json'
|
|
||||||
}
|
|
||||||
return postWithHeaders(url, payload, headers)
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user