Skip to content

solving 2nd assignment#6

Open
TNxRebel wants to merge 1 commit intoTechLabs-Dusseldorf:mainfrom
TNxRebel:main
Open

solving 2nd assignment#6
TNxRebel wants to merge 1 commit intoTechLabs-Dusseldorf:mainfrom
TNxRebel:main

Conversation

@TNxRebel
Copy link

No description provided.

async function main() {
try {
const response = await fetch("https://official-joke-api.appspot.com/random_joke");
const data = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

i would also handle “failed responses” (HTTP status not OK)

if (!response.ok) {
throw new Error(HTTP ${response.status} ${response.statusText});
}

@ibhf13
Copy link
Contributor

ibhf13 commented Dec 29, 2025

well done 💪

async function main() {
try {
const response = await fetch("https://official-joke-api.appspot.com/random_joke");
const data = await response.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

also didnt check for data format

if (typeof data?.setup !== "string" || typeof data?.punchline !== "string") {
throw new Error("Unexpected data format from API");
}

@ibhf13 ibhf13 added the checked PR checked label Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

checked PR checked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants