.then(res => res.ok ? res.json() : Promise.reject(res.text()))
.then(res => res.ok ? res.json() : res.text())
.then(res => if (res !== undefined) return Promise.reject(res))
.catch(e => `Ошибка: ${e}`);
.then(res => res.json())
.then(res => res.users)
.then(res => res.json().users)
При таком коде
.then(res => res.ok ? res.json() : Promise.reject(res.text()))
И еще такой вопрос:
.then(res => res.json())
.then(res => res.users)
почему нельзя сразу возвратить users, вот так?
.then(res => res.json().users)
Body.json()
Takes a Response stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as JSON, which is a JavaScript value of datatype object, string, etc.