From 03f28d3fa6b57d97cfd4933f4f0f232201075f92 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 17 Sep 2018 18:55:11 +0300 Subject: [PATCH] Fixed "user.id is undefined" or something error more sane by properly handling HTTP errors --- src/services/api/api.service.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 87315657..e973667b 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -335,7 +335,14 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&') url += `?${queryString}` - return fetch(url, { headers: authHeaders(credentials) }).then((data) => data.json()) + return fetch(url, { headers: authHeaders(credentials) }) + .then((data) => { + if (data.ok) { + return data + } + throw new Error('Error fetching timeline') + }) + .then((data) => data.json()) } const verifyCredentials = (user) => {