next.js github discussion에 질문을 올린 내용입니다..
https://github.com/vercel/next.js/discussions/49433
notFound()를 사용하면서 이슈를 해결하기 위해 테스트하다보니 여러 케이스를 발견하게 되었습니다. 상세한 로직은 해당 github를 참조하시기 바랍니다. https://github.com/osydoo/next13-not-found
useEffect(()=> {
(async () => {
try{
await axios.get('<http://127.0.0.1:3001/error>'); // 404 error
console.log('success');
}catch(e){
console.log('error')
notFound()
}
})()
}, [])
const [data, setData] = useState('init');
useEffect(()=> {
(async () => {
try{
await axios.get('<http://127.0.0.1:3001/error>'); // 404 error
console.log('success');
}catch(e){
console.log('error')
setData('error')
}
})()
}, [])
useEffect(()=> {
if(data === 'error') {
notFound();
}
}, [data])
const handleClick = async () => {
try{
await axios.get('<http://127.0.0.1:3001/error>'); // 404 error
console.log('success');
}catch(e){
console.log('error')
notFound();
}
}
const axios = _axios.create();
axios.interceptors.response.use(
function(res){
return res
},
function(err){
if(err){
console.log('interceptors')
notFound(); // not working
}
}
)
...
async () => {
try{
await axios.get('<http://127.0.0.1:3001/error>'); // 404 error
console.log('success');
}catch(e){
console.log('error')
notFound()
}
}
const axios = _axios.create();
axios.interceptors.response.use(
function(res){
return res
},
function(err){
if(err){
console.log('interceptors')
notFound();
}
}
)
...
try{
axios.get('<http://127.0.0.1:3001/error>'); // 404 error
console.log('success');
}catch(e){
console.log('error');
notFound();
}