Skip to content

getData fetch, what will happen when res.status!=200 ? #61

Description

@tawfiknasser

function getData(cb) {
fetch("/getquestions")
.then(response => {
if (response.status !== 200) {
console.log(
"Looks like there was a problem. Status Code: " + response.status
);
return;
}
return response.json();
})
.then((myJson) => {
return(cb(myJson));
})
.catch(err => {
console.log("Fetch Error :-S", err);
});
}

when the response status is !200 it will return undefined to the next .then
do you want this to happen ?
return(cb(undefined));
maybe throw error ? or send error in the call back ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions