Skip to content

Commit

Permalink
fix(headers): compatible headers to object
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael A Tomcal committed Aug 26, 2020
1 parent 8451494 commit c97211b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://help.github.com/en/articles/about-code-owners

* @americanexpress/one @americanexpress/one-amex-admins
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { Provider } from 'react-redux';
import { FetchyeReduxProvider } from 'fetchye';
import { fetchyeReducer } from 'fetchye/lib/cache/immutable/reducer';

const store = createStore(reducer);
const store = createStore(fetchyeReducer);

const ParentComponent = ({ children }) => (
<>
Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'scope-case': [2, 'always', ['pascal-case', 'camel-case', 'kebab-case']],
'body-max-line-length': [2, 'always', 150],
},
};
9 changes: 8 additions & 1 deletion src/defaultFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
* permissions and limitations under the License.
*/

// Object.fromEntries is not compatible with Node v10
// provide our own lightweight solution
export const headersToObject = (headers = []) => [...headers]
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});
export const defaultFetcher = async (fetchClient, key, options) => {
let res;
let payload;
Expand All @@ -24,7 +31,7 @@ export const defaultFetcher = async (fetchClient, key, options) => {
payload = {
body,
ok: res.ok,
headers: Object.fromEntries(res.headers?.entries() || []),
headers: headersToObject(res.headers),
status: res.status,
};
} catch (requestError) {
Expand Down

0 comments on commit c97211b

Please sign in to comment.