<aside> 💡

Today’s lesson:

When you use fetch in a function, you need to use .then and .catch when calling that function from another file.

fetch must need .then and .catch

</aside>

스크린샷 2025-10-01 오후 11.54.32.png

I make some function getArticleList using GET method with body.

But there was an TypeError: Request with GET/HEAD method cannot have body.

Throughly examine the error message, I got GET method cannot have HEAD also the body.

Then I thought ‘How can I put lists into request body if I can’t use body with GET?’.

And an idea came across that ‘Maybe only { page, pageSize, keyword} parameter is enough.’ So I erase method, headers, body and const lists.

스크린샷 2025-10-02 오전 12.00.59.png

There is no error in main.js now but the function doesn’t work properly.

스크린샷 2025-10-02 오전 12.03.08.png

Test if it’s only a wrong articleId problem or the function is failed to build well.

I asked to AI, and it said because I don’t have return value in all functions. Therefore I inserted code return res.data; at the end of the all functions.

스크린샷 2025-10-02 오전 12.16.02.png

But it returns ReferenceError: res is not defined.

I look up the answers again, than it saids I should return all of the fetch value using return in front of the fetch.

Change all the functions with return.