//fetch
async request(endPoint) {
try{
const res = await fetch(`${entryPiont}${endPoint}`);
console.log(res)
if(!res.ok){
throw new Error('http Error');
}
return await res.json();
}
catch(e) {
throw new Error(`무언가 잘못되었습니다. ${e.message}`)
}
}
// axios
async request(endPoint) {
try {
const res = await axios.get(`${entryPiont}${endPoint}`)
return res.data;
}
catch(error){
if(error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
}
else if(error.request) {
console.log(error.request);
}
else {
console.log('Error', error.message)
}
console.log(error.config);
}
}
https://developer.mozilla.org/ko/docs/Web/Guide/AJAX/Getting_Started
https://developer.mozilla.org/ko/docs/Web/API/Fetch_API/Using_Fetch
https://xn--xy1bk56a.run/axios/