Skip to content

Commit

Permalink
Merge b823160 into ce15959
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianoratamero committed May 25, 2020
2 parents ce15959 + b823160 commit 2cb79c9
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
2 changes: 1 addition & 1 deletion __tests__/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('apiMiddleware', () => {

it('Should dispatch action success and return the data body - json', async () => {
function get() {
return 'application/json';
return 'application/json; charset=utf-8';
}

const body = {
Expand Down
2 changes: 1 addition & 1 deletion dist/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function buildRequest(url, requestData) {
var request = new Request(url, _objectSpread({}, requestData));
Expand Down
4 changes: 2 additions & 2 deletions dist/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function apiMiddleware(_ref) {
return new Promise(function (resolve, reject) {
apiCallFunction(dispatch).then(function (response) {
// if it's a json response, we unpack and parse it
if (response.headers && typeof response.headers.get === 'function' && response.headers.get('content-type') === 'application/json') {
if (response.headers && typeof response.headers.get === 'function' && response.headers.get('content-type').startsWith('application/json')) {
response.json().then(function (data) {
response.data = data; // from backend response

Expand All @@ -83,7 +83,7 @@ function apiMiddleware(_ref) {
}
}).catch(function (error) {
// if it's a json response, we unpack and parse it
if (error.headers && typeof error.headers.get === 'function' && error.headers.get('content-type') === 'application/json') {
if (error.headers && typeof error.headers.get === 'function' && error.headers.get('content-type').startsWith('application/json')) {
error.json().then(function (data) {
error.data = data; // form backend error

Expand Down
4 changes: 2 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function apiMiddleware({ dispatch, getState }) {
if (
response.headers &&
typeof response.headers.get === 'function' &&
response.headers.get('content-type') === 'application/json'
response.headers.get('content-type').startsWith('application/json')
) {
response.json().then(data => {
response.data = data; // from backend response
Expand All @@ -67,7 +67,7 @@ export default function apiMiddleware({ dispatch, getState }) {
if (
error.headers &&
typeof error.headers.get === 'function' &&
error.headers.get('content-type') === 'application/json'
error.headers.get('content-type').startsWith('application/json')
) {
error.json().then(data => {
error.data = data; // form backend error
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-api-tools",
"version": "2.1.1",
"version": "2.1.2",
"description": "Middleware and helpers to improve the React-Redux flow when communicating with APIs.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2cb79c9

Please sign in to comment.