const proccessFetch = async (
input: URL | RequestInfo,
init?: Omit<RequestInit, 'body'> & { body?: Record<string, any> | null },
) => {
try {
const response = await fetch(
input,
init && {
...init,
headers: {
// 'Content-Type': 'application/json',
...init.headers,
},
body: init.body ? JSON.stringify(init.body) : null,
},
)
if (!response.ok) return Promise.reject(new Error('Response is not ok').message)
return response.status === 200 && response.headers.get('Content-Length') !== '0'
? await response.json()
: null
} catch (err) {
return Promise.reject(new Error(`${JSON.stringify(err)}`).message)
}
}
const proccessFetch = async (
input: URL | RequestInfo,
init?: Omit<RequestInit, 'body'> & { body?: Record<string, any> | null },
) => {
try {
const response = await fetch(
input,
init && {
...init,
headers: {
// 'Content-Type': 'application/json',
...init.headers,
},
body: init.body ? JSON.stringify(init.body) : null,
},
)
if (!response.ok) return Promise.reject(new Error('Response is not ok').message)
return response.status === 200 && response.headers.get('Content-Length') !== '0'
? await response.json()
: null
} catch (err) {
return Promise.reject(new Error(`${JSON.stringify(err)}`).message)
}
}