Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Write a Basic Fetch Request

Richard Preske
PLUS
Richard Preske
Courses Plus Student 4,356 Points

DOG API not same as video

https://w.trhou.se/sh2pq3s1i6

The dog API has been updated. I try fetching with the path in my code see link but I don't get anything in the console but an error.

DevTools failed to load SourceMap: Could not load content for http://port-80-da8h7esxfv.treehouse-app.com/css/styles.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

This is the response:

body: (...) bodyUsed: false headers: Headers {} ok: true redirected: false status: 200 statusText: "" type: "cors" url: "https://dog.ceo/api/breeds/image/random" proto: Response arrayBuffer: ƒ arrayBuffer() blob: ƒ blob() body: (...) bodyUsed: (...) clone: ƒ clone() formData: ƒ formData() headers: (...) json: ƒ json() ok: (...) redirected: (...) status: (...) statusText: (...) text: ƒ text() type: (...) url: (...) constructor: ƒ Response() Symbol(Symbol.toStringTag): "Response" get body: ƒ body() get bodyUsed: ƒ bodyUsed() get headers: ƒ headers() get ok: ƒ ok() get redirected: ƒ redirected() get status: ƒ status() get statusText: ƒ statusText() get type: ƒ type() get url: ƒ url() proto: Object

2 Answers

Steven Parker
Steven Parker
231,269 Points

I don't get the error when I try it. But the file it was looking for (css/styles.css.map) is not part of the project, and not related to the API.

But in the API response from the fetch it says it worked:

status: 200 :point_left: this is a success code
ok: true

Richard Preske
Richard Preske
Courses Plus Student 4,356 Points

Is my path correct in the fetch() API? It says false status: 200 on the first line

Steven Parker
Steven Parker
231,269 Points

The "false" goes with the previous keyword "redirected". The "status" is 200, and that's the code for success.

The path is correct. As you continue with the project, you will soon display the image on the screen and you'll see the proof!