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 [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')
setInfo('...loading')
axios.post('https://neko-cafe-back.herokuapp.com/auth/test', {success: x})
axios
.post(url, {success: x})
.then(res => {
setAnswer(res.data.errorText)
setInfo(res.data.info)
})
.catch(e => {
setAnswer(e.response.data.errorText)
setInfo(e.response.data.info)
setAnswer(e.response?.data?.errorText || e.message)
setInfo(e.response?.data?.info || e.name)
})
}
@@ -50,6 +53,13 @@ const HW13 = () => {
>
send undefined
</SuperButton>
<SuperButton
id={'hw13-send-null'}
onClick={send(null)}
disabled={answer === '...loading'}
>
send null
</SuperButton>
<div id={'hw13-answer'}>
{answer}