Skip to content

Commit 1435153

Browse files
author
Martin Krulis
committed
Fixing bug in testing http response codes.
1 parent 3531d6a commit 1435153

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/redux/helpers/api/tools.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import { actionTypes as authActionTypes } from '../../modules/authTypes';
1212
export const isTwoHundredCode = status => statusCode.accept(status, '2xx');
1313
export const isServerError = status => statusCode.accept(status, '5xx');
1414
export const isUnauthorized = status => status === 403;
15+
const isStatusOKWithBody = status =>
16+
status === 200 || // OK
17+
status === 201 || // Created
18+
status === 202 || // Accepted
19+
status === 203 || // Non-auth info
20+
status === 206; // Partial content
1521

1622
const maybeShash = endpoint => (endpoint.indexOf('/') === 0 ? '' : '/');
1723
const getUrl = endpoint => API_BASE + maybeShash(endpoint) + endpoint;
@@ -194,12 +200,12 @@ const detectUnreachableServer = (err, dispatch) => {
194200
const processResponse = (call, dispatch) =>
195201
call
196202
.then(res => {
197-
if (res.status !== 200) {
198-
return Promise.reject(res);
203+
if (isStatusOKWithBody(res.status)) {
204+
return res.json();
199205
}
200-
return res.json();
206+
return Promise.reject(res);
201207
})
202-
.then(({ success = true, code, error = null, payload = {} }) => {
208+
.then(({ success = true, error = null, payload = {} }) => {
203209
if (!success) {
204210
if (error && error.message) {
205211
dispatch && dispatch(addNotification(`Server response: ${error.message}`, false));

0 commit comments

Comments
 (0)