add network error hw 13

This commit is contained in:
neko
2022-06-19 22:40:05 +03:00
parent 10b630c34b
commit 783083d02a

View File

@@ -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}