@@ -12,6 +12,12 @@ import { actionTypes as authActionTypes } from '../../modules/authTypes';
1212export const isTwoHundredCode = status => statusCode . accept ( status , '2xx' ) ;
1313export const isServerError = status => statusCode . accept ( status , '5xx' ) ;
1414export 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
1622const maybeShash = endpoint => ( endpoint . indexOf ( '/' ) === 0 ? '' : '/' ) ;
1723const getUrl = endpoint => API_BASE + maybeShash ( endpoint ) + endpoint ;
@@ -194,12 +200,12 @@ const detectUnreachableServer = (err, dispatch) => {
194200const 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