You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -73,11 +75,13 @@ See the changes in the [beta's documentation](https://github.com/agraboso/redux-
73
75
-[`[RSAA].credentials`](#rsaacredentials-1)
74
76
-[`[RSAA].bailout`](#rsaabailout)
75
77
-[`[RSAA].fetch`](#rsaafetch-1)
78
+
-[`[RSAA].ok`](#rsaaok)
76
79
-[`[RSAA].types`](#rsaatypes)
77
80
-[Type descriptors](#type-descriptors)
78
81
-[History](#history)
79
82
-[Tests](#tests)
80
83
-[Upgrading from v1.0.x](#upgrading-from-v10x)
84
+
-[Upgrading from v2.0.x](#upgrading-from-v20x)
81
85
-[License](#license)
82
86
-[Projects using redux-api-middleware](#projects-using-redux-api-middleware)
83
87
-[Acknowledgements](#acknowledgements)
@@ -142,6 +146,10 @@ We have tiptoed around error-handling issues here. For a thorough walkthrough of
142
146
143
147
See the [2.0 Release Notes](https://github.com/agraboso/redux-api-middleware/releases/tag/v2.0.0), and [Upgrading from v1.0.x](#upgrading-from-v10x) for details on upgrading.
144
148
149
+
### Breaking Changes in3.0 Release
150
+
151
+
See the [3.0 Release Notes](https://github.com/agraboso/redux-api-middleware/releases/tag/v3.0.0), and [Upgrading from v2.0.x](#upgrading-from-v20x) for details on upgrading.
152
+
145
153
## Installation
146
154
147
155
`redux-api-middleware` is available on [npm](https://www.npmjs.com/package/redux-api-middleware).
@@ -370,8 +378,8 @@ The `[RSAA].types` property controls the output of `redux-api-middleware`. The s
370
378
- `fetch` may throw an error: the RSAA definition is not strong enough to preclude that from happening (you may, for example, send in a `[RSAA].body` that is not valid according to the fetch specification — mind the SHOULDs in the [RSAA definition](#redux-standard-api-calling-actions));
371
379
- a network failure occurs (the network is unreachable, the server responds with an error,...).
372
380
373
-
If such an error occurs, a different *request* FSA will be dispatched (*instead* of the one described above). It will contain the following properties:
374
-
- `type`: the string constant in the first position of the `[RSAA].types` array;
381
+
If such an error occurs, a *failure* FSA will be dispatched containing the following properties:
382
+
- `type`: the string constant in the last position of the `[RSAA].types` array;
375
383
- `payload`: a [`RequestError`](#requesterror) object containing an error message;
376
384
- `error:true`.
377
385
@@ -409,7 +417,7 @@ See [the Redux docs on composition](https://github.com/reduxjs/redux-thunk#compo
@@ -670,6 +678,7 @@ For example, if you want the status code and status message of a unsuccessful AP
670
678
}
671
679
}
672
680
```
681
+
673
682
By default, *failure* FSAs will not contain a `meta` property, while their `payload` property will be evaluated from
674
683
```js
675
684
(action, state, res) =>
@@ -678,6 +687,9 @@ By default, *failure* FSAs will not contain a `meta` property, while their `payl
678
687
)
679
688
```
680
689
690
+
691
+
Note that *failure* FSAs dispatched due to fetch errors will not have a `res` argument into `meta` or `payload`. The `res` parameter will exist for completed requests that have resulted in errors, but not for failed requests.
692
+
681
693
### Exports
682
694
683
695
The following objects are exported by `redux-api-middleware`.
@@ -690,6 +702,15 @@ A JavaScript `String` whose presence as a key in an action signals that `redux-a
690
702
691
703
The Redux middleware itself.
692
704
705
+
#### `createMiddleware(options)`
706
+
707
+
A function that creates an `apiMiddleware` with custom options.
708
+
709
+
The following `options` properties are used:
710
+
711
+
- `fetch` - provide a `fetch` API compatible function here to use instead of the default `window.fetch`
712
+
- `ok` - provide a function here to use as a status check in the RSAA flow instead of `(res) =>res.ok`
713
+
693
714
#### `isRSAA(action)`
694
715
695
716
A function that returns `true` if `action` has an `[RSAA]` property, and `false` otherwise.
@@ -802,9 +823,9 @@ A *Redux Standard API-calling Action* MUST
802
823
- be a plain JavaScript object,
803
824
- have an `[RSAA]` property.
804
825
805
-
A *Redux Standard API-calling Action* MUST NOT
826
+
A *Redux Standard API-calling Action* MAY
806
827
807
-
- include properties other than `[RSAA]`.
828
+
- include properties other than `[RSAA]` (but will be ignored by redux-api-middleware).
808
829
809
830
#### `[RSAA]`
810
831
@@ -822,11 +843,12 @@ The `[RSAA]` property MAY
822
843
- have an `options` property,
823
844
- have a `credentials` property,
824
845
- have a `bailout` property,
825
-
- have a `fetch` property.
846
+
- have a `fetch` property,
847
+
- have an `ok` property.
826
848
827
849
The `[RSAA]` property MUST NOT
828
850
829
-
- include properties other than `endpoint`, `method`, `types`, `body`, `headers`, `options`, `credentials`, `bailout`and `fetch`.
851
+
- include properties other than `endpoint`, `method`, `types`, `body`, `headers`, `options`, `credentials`, `bailout`, `fetch`and `ok`.
830
852
831
853
#### `[RSAA].endpoint`
832
854
@@ -860,7 +882,11 @@ The optional `[RSAA].bailout` property MUST be a boolean or a function.
860
882
861
883
#### `[RSAA].fetch`
862
884
863
-
The optional `[RSAA].fetch` property MUST be a function.
885
+
The optional `[RSAA].fetch` property MUST be a function that conforms to the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
886
+
887
+
#### `[RSAA].ok`
888
+
889
+
The optional `[RSAA].ok` property MUST be a function that accepts a response object and returns a boolean indicating if the request is a success or failure
864
890
865
891
#### `[RSAA].types`
866
892
@@ -899,6 +925,13 @@ $ npm install && npm test
899
925
- A new `options` config is added to pass your `fetch` implementation extra options other than `method`, `headers`, `body` and `credentials`
900
926
- `apiMiddleware` no longer returns a promise on actions without [RSAA]
901
927
928
+
## Upgrading from v2.0.x
929
+
930
+
- The `CALL_API` alias has been removed
931
+
- Error handling around failed fetches has been updated (#175)
932
+
- Previously, a failed `fetch` would dispatch a `REQUEST` FSA followed by another `REQUEST` FSA with an error flag
933
+
- Now, a failed `fetch` will dispatch a `REQUEST` FSA followed by a `FAILURE` FSA
0 commit comments