Skip to content

Commit

Permalink
feat: integrate http status code
Browse files Browse the repository at this point in the history
  • Loading branch information
edysegura committed Jan 16, 2025
1 parent 6398c07 commit cc8b024
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions handling-fetch/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
async function doRequest() {
async function doRequest(httpStatusCode = 200) {
const output = document.querySelector('p')
let response
try {
response = await fetch('https://httpstat.us/400')
response = await fetch(`https://httpstat.us/${httpStatusCode}`)
if (response.ok) {
output.innerHTML = `${response.status}: ${response.statusText}`
return response
}
throw new Error(`Error: Response status ${response.status}`)
throw new Error(`${response.status}: ${response.statusText}`)
} catch (error) {
output.innerHTML = error
return error
}
}
2 changes: 1 addition & 1 deletion handling-fetch/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<button onclick="doRequest(200)">HTTP 200</button>
<button onclick="doRequest(404)">HTTP 404</button>
<button onclick="doRequest(500)">HTTP 500</button>
<output></output>
<p></p>
</body>
</html>

0 comments on commit cc8b024

Please sign in to comment.