mirror of
https://github.com/xodio/xod.git
synced 2026-03-25 01:56:54 +01:00
30 lines
831 B
JavaScript
30 lines
831 B
JavaScript
import * as R from 'ramda';
|
|
|
|
/**
|
|
* Universal function, that normilizes fetch result to
|
|
* rejected Promise. Useful to use with `retryOrFail` as `errFn`.
|
|
*
|
|
* There is two possible cases for `res` argument:
|
|
* - contains Error object (E.G. network error)
|
|
* it will just merge a payload to the Error.
|
|
* - contains response object (E.G. unwanted response status)
|
|
* it will create new Error with statusText and merged
|
|
* status, statusText and payload
|
|
*/
|
|
// :: Object -> (FetchResult | Error) -> Error
|
|
export const rejectFetchResult = R.curry(
|
|
(payload, res) =>
|
|
res.status
|
|
? Object.assign(
|
|
new Error(res.statusText),
|
|
{
|
|
status: res.status,
|
|
statusText: res.statusText,
|
|
},
|
|
payload
|
|
)
|
|
: Object.assign(res, payload)
|
|
);
|
|
|
|
export default {};
|