mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Posting using formData
This commit is contained in:
@ -18,28 +18,29 @@ const client = async ({
|
||||
query?: {
|
||||
[key: string]: string | number | boolean
|
||||
}
|
||||
body?: object
|
||||
body?: FormData
|
||||
}): Promise<any> => {
|
||||
const state: RootState['instanceInfo'] = store.getState().instanceInfo
|
||||
|
||||
let response
|
||||
try {
|
||||
response = await ky(endpoint, {
|
||||
method: method,
|
||||
prefixUrl: `https://${state[instance]}/api/${version}`,
|
||||
searchParams: query,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...headers,
|
||||
...(instance === 'local' && {
|
||||
Authorization: `Bearer ${state.localToken}`
|
||||
})
|
||||
},
|
||||
...(body && { json: body })
|
||||
})
|
||||
} catch (error) {
|
||||
return Promise.reject('ky error: ' + error)
|
||||
}
|
||||
// try {
|
||||
response = await ky(endpoint, {
|
||||
method: method,
|
||||
prefixUrl: `https://${state[instance]}/api/${version}`,
|
||||
searchParams: query,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...headers,
|
||||
...(instance === 'local' && {
|
||||
Authorization: `Bearer ${state.localToken}`
|
||||
})
|
||||
},
|
||||
...(body && { body: body }),
|
||||
throwHttpErrors: false
|
||||
})
|
||||
// } catch (error) {
|
||||
// return Promise.reject('ky error: ' + error.json())
|
||||
// }
|
||||
|
||||
if (response.ok) {
|
||||
return Promise.resolve({
|
||||
@ -47,8 +48,9 @@ const client = async ({
|
||||
body: await response.json()
|
||||
})
|
||||
} else {
|
||||
console.error(response.status + ': ' + response.statusText)
|
||||
return Promise.reject({ body: response.statusText })
|
||||
const errorResponse = await response.json()
|
||||
console.error(response.status + ': ' + errorResponse.error)
|
||||
return Promise.reject({ body: errorResponse.error })
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user