일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- revalidatepath
- 클로저
- createbrowserrouter
- commit phase
- dynamic pages
- interceptor routes
- server components
- 3진법 뒤집기
- static pages
- @tailwind base
- @tailwind
- 리액트
- @tailwind components
- 타입스크립트
- CSS
- iron-session
- @tailwind utility
- 자바스크립트
- supabase realtime
- image component
- SSR
- sever action
- 프로그래머스
- js
- revalidatetag
- sever components
- render phase
- client components
- unstable_nostore
- RECOIL
Archives
- Today
- Total
개발하는 너구리
TIL.23.06.28 본문
문제점
axios로 통신하는 try{} catch(error) {} 구문에서 error의 타입을 지정하는 법
시도한점
error의 타입은 어떠한 타입이 들어올지 특정할수없기에, 찾아보니 많이들 any 타입을 설정하는걸 보았다.
그러나, 나는 axios로 통신하는 코드에서의 error이므로 AxiosError라는 객체라는 것을 알았고를 그것을 가져와 error의 타입으로 지정했다.
import { AxiosError } from 'axios';
catch (error) {
const axiosError = error as AxiosError;
if (axiosError?.response?.data === '존재하지 않는 사용자입니다.') {
toast.error('방송을 먼저 생성해주세요');
}
}
'TIL' 카테고리의 다른 글
TIL-24.04.17 (0) | 2024.04.17 |
---|---|
TIL-24.04.16 (0) | 2024.04.16 |
TIL-23.06.27 (0) | 2023.06.27 |
TIL-23.06.23 (0) | 2023.06.23 |
TIL-23.06.12 (0) | 2023.06.13 |