mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import axios from 'axios'
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export const apiPost = async (url: string, payload: unknown): Promise<any> => {
|
|
return axios
|
|
.post(url, payload)
|
|
.then((result) => {
|
|
if (result.status !== 200) {
|
|
throw new Error('HTTP Status Error ' + result.status)
|
|
}
|
|
if (result.data.state !== 'success') {
|
|
throw new Error(result.data.msg)
|
|
}
|
|
return { success: true, data: result.data }
|
|
})
|
|
.catch((error) => {
|
|
return { success: false, data: error.message }
|
|
})
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export const apiGet = async (url: string): Promise<any> => {
|
|
return axios
|
|
.get(url)
|
|
.then((result) => {
|
|
if (result.status !== 200) {
|
|
throw new Error('HTTP Status Error ' + result.status)
|
|
}
|
|
if (!['success', 'warning'].includes(result.data.state)) {
|
|
throw new Error(result.data.msg)
|
|
}
|
|
return { success: true, data: result.data }
|
|
})
|
|
.catch((error) => {
|
|
return { success: false, data: error.message }
|
|
})
|
|
}
|