Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix Parsing Error & TypeError #23

Merged
merged 6 commits into from
Nov 19, 2024
Merged

fix: fix Parsing Error & TypeError #23

merged 6 commits into from
Nov 19, 2024

Conversation

gahyuun
Copy link
Member

@gahyuun gahyuun commented Nov 8, 2024

๐Ÿ“Œ ์ž‘์—… ๋‚ด์šฉ

๊ตฌํ˜„ ๋‚ด์šฉ ๋ฐ ์ž‘์—… ํ–ˆ๋˜ ๋‚ด์—ญ

closed #21
closed #22

  • headers ๊ฐ์ฒด Record<string,string> ํƒ€์ž…์œผ๋กœ ์ง€์ •
  • baseURL๊ณผ url์„ new URL์„ ํ†ตํ•ด ํ•ฉ์น˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ url์ด ์ƒ๋Œ€ ๊ฒฝ๋กœ์ผ ๊ฒฝ์šฐ์—๋งŒ ๋ฌธ์ž์—ด ํ•ฉ์น˜๋Š” ํ˜•์‹์œผ๋กœ ๋ณ€๊ฒฝ
  • isBodyInit ํ•จ์ˆ˜์—์„œ data type์„ ํ™•์ธํ•  ๋•Œ data๊ฐ€ JSON ํƒ€์ž…์ด๋ฉด typeof data === 'string' ์กฐ๊ฑด๋ฌธ์—์„œ true๋”๋ผ๊ตฌ์š” ํ•˜์ง€๋งŒ ์กฐ๊ธˆ ๋” ๋ช…์‹œ์ ์ด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„ isJSON ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ ํ›„ ์กฐ๊ฑด๋ฌธ์— ์ถ”๊ฐ€ํ•ด์คฌ์Šต๋‹ˆ๋‹ค

๐Ÿ”Š ๋„์›€์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„

  • baseURL์ด ์ง€์ •๋˜์–ด ์žˆ์ง€ ์•Š์€ ์ƒํƒœ์—์„œ '/user/sr'์™€ ๊ฐ™์€ ์ƒ๋Œ€ ๊ฒฝ๋กœ๋ฅผ ๋„ฃ์œผ๋ฉด Invalid URL ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. (๊ทธ๋ž˜์„œ URL ์ชฝ ์ผ๋ถ€๋ฅผ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.) baseURL ์ง€์ •์ด ์•ˆ ๋˜์–ด ์žˆ์„ ๋•Œ ํ•ด๋‹น origin์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋„๋ก ๊ฐœ์„ ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. (Migration ax fetchย myongji-graduate-next#149)
  • ์ €๋ฒˆ PR์—์„œ baseURL์ด ์—†๋Š” ์ƒํƒœ์—์„œ /user/sr ์ƒ๋Œ€ ๊ฒฝ๋กœ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด InvalidURL Error๊ฐ€ ์•„๋‹Œ origin์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ํ•˜์…จ๋Š”๋ฐ, /user/sr๋กœ ๋ณด๋‚ด๋„ ์–ด์ฐจํ”ผ Fetch API์—์„œ InvalidError๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋”๋ผ๊ตฌ์š” fetch-ax์—์„œ InvalidError๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š๊ฒŒ ์ˆ˜์ •์„ ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”??
  • ์ €๋„ Fetch API์—์„œ InvalidError ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๊ฑธ ๋’ค๋Šฆ๊ฒŒ ํ™•์ธํ•ด์„œ ์ผ๋‹จ ๊ตฌํ˜„์€ ๋œ ์ƒํƒœ์ด๋ฉฐ baseURL, url ๋‘˜๋‹ค ์žˆ๋Š”๋ฐ ๋งŒ์•ฝ url์ด ์ ˆ๋Œ€๊ฒฝ๋กœ๋ผ๋ฉด baseURL์ด ๋ฌด์‹œ๋˜๋Š” ๊ธฐ๋Šฅ๋„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
TypeError: Failed to parse URL from sign-in
  [cause]: TypeError: Invalid URL

@gahyuun gahyuun added the bug Something isn't working label Nov 8, 2024
@gahyuun gahyuun requested a review from seonghunYang November 8, 2024 06:15
@gahyuun gahyuun self-assigned this Nov 8, 2024
@gahyuun gahyuun requested a review from yougyung as a code owner November 8, 2024 06:15
@gahyuun gahyuun changed the title fix: fix InvalidURL Error fix: fix Parsing Error Nov 8, 2024
@gahyuun gahyuun changed the title fix: fix Parsing Error fix: fix Parsing Error & TypeError Nov 8, 2024
Comment on lines +241 to +246
const buildFullPath = (baseURL: string | undefined, requestedURL: string) => {
if (baseURL && !isAbsoluteURL(requestedURL)) {
return combineURLs(baseURL, requestedURL);
}
return requestedURL;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • baseURL์ด ์—†๊ณ  ์ ˆ๋Œ€ URL์ด ์•„๋‹Œ ๊ฒฝ์šฐ์—๋Š” fetch์—์„œ Invalid URL ๋ฐœ์ƒํ•˜๋„๋ก ์œ ๋„ํ•œ๊ฑด๊ฐ€์—ฌ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ค๋„ต ! "/a" ์ด๋Ÿฐ ์‹์œผ๋กœ ์š”์ฒญ ํ–ˆ์„๋•Œ fetch์—์„œ InvalidURL Error๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋”๋ผ๊ตฌ์š” ๊ทธ๋ž˜์„œ ์ œ๊ฐ€ ์ƒ๊ฐํ•˜๊ธฐ์—” ์ €ํฌ๊ฐ€ InvalidURL์„ ๊ตณ์ด ์ฝ”๋“œ๋กœ ๋ง‰์„ ํ•„์š”๊ฐ€ ์—†๋‹ค๊ณ  ๋Š๊ผˆ์Šต๋‹ˆ๋‹ค!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ๋ฐ‘์— ์˜๊ฒฌ ๋‚จ๊ธด๊ฑฐ๋ž‘ ๋™์ผํ•œ ๊ฒƒ ๊ฐ™์€๋ฐ axios์˜ ๊ฒฝ์šฐ๋Š” ์ ˆ๋Œ€ ๊ฒฝ๋กœ๊ฐ€ ์•„๋‹Œ ์ƒ๋Œ€ ๊ฒฝ๋กœ๊ฐ€ ์ž…๋ ฅ๋  ๋•Œ baseURL์ด ์—†์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ origin ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ  ์žˆ๊ณ , ์ œ ์‚ฌ์šฉ ๊ฒฝํ—˜์„ ๊ณ ๋ คํ–ˆ์„ ๋•Œ๋„ ์ €๋Š” ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ค์–ด์š”
  • ๋‹ค๋งŒ, ์ด PR์ด๋ž‘ ๋ณ„๊ฐœ์˜ ์ž‘์—…์œผ๋กœ ๋”ฐ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๋”ฐ๋กœ issue๋ฅผ ๋งŒ๋“ค์–ด ๋†“๊ณ  ๋‹ค์Œ PR์—์„œ ์ œ๊ฐ€ ์ฒ˜๋ฆฌํ•ด๋ณด๋„๋ก ํ• ๊ฒŒ์š”!

Copy link
Member Author

@gahyuun gahyuun Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„ํ•˜ ๊ทธ๋Ÿฌ๋ฉด ๋งŒ์•ฝ ์•„๋ž˜์™€ ๊ฐ™์ด baseURL์ด ์—†๊ณ  ์ƒ๋Œ€ ๊ฒฝ๋กœ๋งŒ ์žˆ์„ ๋•Œ ํด๋ผ์ด์–ธํŠธ์ฃผ์†Œ/a (ex. http://localhost:3000/a)๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ๊ฒŒ ๋งž์„๊นŒ์š”??
์ €๋Š” ์ฒ˜์Œ์— baseURL์ด ์—†๊ณ  /a๊ฐ€ ์—†๋Š”๋ฐ ์„œ๋ฒ„ ๋„๋ฉ”์ธ์„ ์–ด๋–ป๊ฒŒ ์•Œ๊ณ  ์š”์ฒญ์„ ๋ณด๋‚ด์ง€? ๋ผ๋Š” ์ƒ๊ฐ ๋•Œ๋ฌธ์— ์ดํ•ด๋ฅผ ํ•œ ๋ฒˆ์— ํ•˜์ง€ ๋ชปํ•œ ๊ฒƒ ๊ฐ™์•„์š” ๐Ÿฅน

const response = await fetch-ax('/a', {
          headers: {},
          // @ts-ignore
        });

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋„ค ๋งž์Šต๋‹ˆ๋‹ค!

@seonghunYang
Copy link
Contributor

  • ์ €๋ฒˆ PR์—์„œ baseURL์ด ์—†๋Š” ์ƒํƒœ์—์„œ /user/sr ์ƒ๋Œ€ ๊ฒฝ๋กœ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด InvalidURL Error๊ฐ€ ์•„๋‹Œ origin์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ํ•˜์…จ๋Š”๋ฐ, /user/sr๋กœ ๋ณด๋‚ด๋„ ์–ด์ฐจํ”ผ Fetch API์—์„œ InvalidError๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋”๋ผ๊ตฌ์š” fetch-ax์—์„œ InvalidError๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š๊ฒŒ ์ˆ˜์ •์„ ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”??

axios์˜ ๊ฒฝ์šฐ, ์ ˆ๋Œ€ ๊ฒฝ๋กœ๊ฐ€ ์•„๋‹Œ ์ƒ๋Œ€ ๊ฒฝ๋กœ๊ฐ€ ์ž…๋ ฅ๋  ๋•Œ baseURL์ด ์—†์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ origin์„ ์š”์ฒญ์œผ๋กœ ๋ณด๋ƒ…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ฐœ๋ฐœ ํŽธ์˜์„ฑ์„ ์œ„ํ•ด ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์ด๋ผ๊ณ  ํŒ๋‹จํ•˜์—ฌ ์ œ์•ˆ๋“œ๋ ธ์Šต๋‹ˆ๋‹ค.

Copy link
Member

@yougyung yougyung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค.
exampleํด๋”์˜ interceptor์™€ README๋„ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ๋ฐ˜์˜๋˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

@gahyuun
Copy link
Member Author

gahyuun commented Nov 16, 2024

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค. exampleํด๋”์˜ interceptor์™€ README๋„ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ๋ฐ˜์˜๋˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!

ํ—‰ ํฐ์ผ๋‚ ๋ป”ํ–ˆ๋„ค์š”ใ… ใ…  ๋ง์”€ํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค
7ee068c

@gahyuun gahyuun merged commit 93d664a into main Nov 19, 2024
@gahyuun gahyuun deleted the fix/parsing-error branch November 19, 2024 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

data type is already JSON headers Init Type Error
3 participants