mirror of
https://github.com/IgnatZakalinsky/home-works.git
synced 2026-01-28 20:42:04 +00:00
add network error hw 13
This commit is contained in:
@@ -7,17 +7,20 @@ const HW13 = () => {
|
|||||||
const [answer, setAnswer] = useState('')
|
const [answer, setAnswer] = useState('')
|
||||||
const [info, setInfo] = useState('')
|
const [info, setInfo] = useState('')
|
||||||
|
|
||||||
const send = (x?: boolean) => () => {
|
const send = (x?: boolean | null) => () => {
|
||||||
|
const url = x === null ? 'https://xxxxxx.ccc' : 'https://neko-cafe-back.herokuapp.com/auth/test'
|
||||||
|
|
||||||
setAnswer('...loading')
|
setAnswer('...loading')
|
||||||
setInfo('...loading')
|
setInfo('...loading')
|
||||||
axios.post('https://neko-cafe-back.herokuapp.com/auth/test', {success: x})
|
axios
|
||||||
|
.post(url, {success: x})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setAnswer(res.data.errorText)
|
setAnswer(res.data.errorText)
|
||||||
setInfo(res.data.info)
|
setInfo(res.data.info)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
setAnswer(e.response.data.errorText)
|
setAnswer(e.response?.data?.errorText || e.message)
|
||||||
setInfo(e.response.data.info)
|
setInfo(e.response?.data?.info || e.name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +53,13 @@ const HW13 = () => {
|
|||||||
>
|
>
|
||||||
send undefined
|
send undefined
|
||||||
</SuperButton>
|
</SuperButton>
|
||||||
|
<SuperButton
|
||||||
|
id={'hw13-send-null'}
|
||||||
|
onClick={send(null)}
|
||||||
|
disabled={answer === '...loading'}
|
||||||
|
>
|
||||||
|
send null
|
||||||
|
</SuperButton>
|
||||||
|
|
||||||
<div id={'hw13-answer'}>
|
<div id={'hw13-answer'}>
|
||||||
{answer}
|
{answer}
|
||||||
|
|||||||
Reference in New Issue
Block a user