mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
refactor: split showErrorApi function
This commit is contained in:
@@ -5,6 +5,7 @@ import {Connector, getConnectors, postConnector} from "../../utils/api/connector
|
||||
import {ConnectorForm} from "../../components/tracking/ConnectorForm";
|
||||
import {AxiosError} from "axios";
|
||||
import {ConnectorElement, ConnectorsList} from "../../components/tracking/ConnectorsList";
|
||||
import {showErrorAPI} from "../../utils";
|
||||
|
||||
export default function ConnectorsPage() {
|
||||
const [form] = Form.useForm()
|
||||
@@ -17,17 +18,15 @@ export default function ConnectorsPage() {
|
||||
refreshConnectors()
|
||||
messageApi.success(t`Connector created !`)
|
||||
}).catch((e: AxiosError) => {
|
||||
const data = e?.response?.data as { detail: string }
|
||||
messageApi.error(data.detail ?? t`An error occurred`)
|
||||
showErrorAPI(e, messageApi)
|
||||
})
|
||||
}
|
||||
|
||||
const refreshConnectors = () => getConnectors().then(c => {
|
||||
setConnectors(c['hydra:member'])
|
||||
}).catch((e: AxiosError) => {
|
||||
const data = e?.response?.data as { detail: string }
|
||||
messageApi.error(data.detail ?? t`An error occurred`)
|
||||
setConnectors(undefined)
|
||||
showErrorAPI(e, messageApi)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {t} from 'ttag'
|
||||
import {WatchlistForm} from "../../components/tracking/WatchlistForm";
|
||||
import {WatchlistsList} from "../../components/tracking/WatchlistsList";
|
||||
import {Connector, getConnectors} from "../../utils/api/connectors";
|
||||
import {showErrorAPI} from "../../utils";
|
||||
|
||||
|
||||
export type Watchlist = {
|
||||
@@ -45,17 +46,15 @@ export default function WatchlistPage() {
|
||||
refreshWatchlists()
|
||||
messageApi.success(t`Watchlist created !`)
|
||||
}).catch((e: AxiosError) => {
|
||||
const data = e?.response?.data as { detail: string }
|
||||
messageApi.error(data?.detail ?? t`An error occurred`)
|
||||
showErrorAPI(e, messageApi)
|
||||
})
|
||||
}
|
||||
|
||||
const refreshWatchlists = () => getWatchlists().then(w => {
|
||||
setWatchlists(w['hydra:member'])
|
||||
}).catch((e: AxiosError) => {
|
||||
const data = e?.response?.data as { detail: string }
|
||||
messageApi.error(data?.detail ?? t`An error occurred`)
|
||||
setWatchlists(undefined)
|
||||
showErrorAPI(e, messageApi)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
@@ -63,8 +62,7 @@ export default function WatchlistPage() {
|
||||
getConnectors()
|
||||
.then(c => setConnectors(c['hydra:member']))
|
||||
.catch((e: AxiosError) => {
|
||||
const data = e?.response?.data as { detail: string }
|
||||
messageApi.error(data?.detail ?? t`An error occurred`)
|
||||
showErrorAPI(e, messageApi)
|
||||
})
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user