-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathzipcar.js
26 lines (23 loc) · 909 Bytes
/
zipcar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createAction } from 'redux-actions'
if (typeof (fetch) === 'undefined') require('isomorphic-fetch')
export const receivedZipcarLocationsError = createAction('ZIPCAR_LOCATIONS_ERROR')
export const receivedZipcarLocationsResponse = createAction('ZIPCAR_LOCATIONS_RESPONSE')
export const requestZipcarLocationsResponse = createAction('ZIPCAR_LOCATIONS_REQUEST')
export function zipcarLocationsQuery (url) {
return async function (dispatch, getState) {
dispatch(requestZipcarLocationsResponse())
let json
try {
const response = await fetch(url)
if (response.status >= 400) {
const error = new Error('Received error from server')
error.response = response
throw error
}
json = await response.json()
} catch (err) {
return dispatch(receivedZipcarLocationsError(err))
}
dispatch(receivedZipcarLocationsResponse(json))
}
}